Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.databases.ms-sqlserver > #1332

Re: SSE2008 money Type

From Erland Sommarskog <esquel@sommarskog.se>
Newsgroups comp.databases.ms-sqlserver, microsoft.public.sqlserver.programming
Subject Re: SSE2008 money Type
Followup-To comp.databases.ms-sqlserver
Date 2012-10-11 11:16 +0000
Organization Erland Sommarskog
Message-ID <XnsA0E9870A87B52Yazorman@127.0.0.1> (permalink)
References <mqcc78906k2avdq0uuj25nem4r5b4qnsnp@4ax.com>

Cross-posted to 2 groups.

Followups directed to: comp.databases.ms-sqlserver

Show all headers | View raw


Gene Wirchenko (genew@ocis.net) writes:
> print 12.345;     -- prints 12.345
> print convert(money,12.345);     -- prints 12.35
> print 12.35-convert(money,12.345);     -- prints 0.0050
> print convert(money,12.35)-convert(money,12.345);     -- prints 0.01
> print 12.345+convert(money,12.345)-12.345;     -- prints 12.3450
> 
>      The precision is apparently there per the third statement, but
> how do I force it?  I have tried variations with the second statement,
> but I have been unable to get it to output 12.345.  How is it that the
> third statement gives four decimal digits, but the second and fourth
> do not?  The fifth statement is just plain weird.

You are confusing precision with print format and the conversion to varchar.

Apparently money is converted to varchar without display of trailing zeroes. 
The decimal data type is not. And when you add a number like 12.35 you are 
in decimal land, since the data type of 12.35 is decimal(5,2).

Use the str() function to get trailing zeroes:

declare @m money = 1.234
select str(@m, 6, 4)


-- 
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

Back to comp.databases.ms-sqlserver | Previous | NextPrevious in thread | Find similar


Thread

SSE2008 money Type Gene Wirchenko <genew@ocis.net> - 2012-10-10 19:47 -0700
  Re: SSE2008 money Type "Bob Barrows" <reb01501@NOSPAMyahoo.com> - 2012-10-11 06:40 -0400
    Re: SSE2008 money Type rja.carnegie@gmail.com - 2012-10-11 04:45 -0700
      Re: SSE2008 money Type "Bob Barrows" <reb01501@NOyahooSPAM.com> - 2012-10-11 12:53 -0400
  Re: SSE2008 money Type Erland Sommarskog <esquel@sommarskog.se> - 2012-10-11 11:16 +0000

csiph-web