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


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

Re: SSE2008 money Type

From "Bob Barrows" <reb01501@NOSPAMyahoo.com>
Newsgroups comp.databases.ms-sqlserver, microsoft.public.sqlserver.programming
Subject Re: SSE2008 money Type
Date 2012-10-11 06:40 -0400
Organization A noiseless patient Spider
Message-ID <k567n0$3ul$1@dont-email.me> (permalink)
References <mqcc78906k2avdq0uuj25nem4r5b4qnsnp@4ax.com>

Cross-posted to 2 groups.

Show all headers | View raw


Gene Wirchenko wrote:
> Dear SQLers:
>
>     According to Microsoft
> http://msdn.microsoft.com/en-us/library/aa258271%28v=sql.80%29.aspx
> money has four decimal digits.  Unfortunately, if I use print to check
> things, I sometimes do not get the four digits displayed as in:
>
You're being caught by implicit conversions to varchar.

> print 12.345;     -- prints 12.345

Implicit conversion to varchar using the default style setting for float or 
real data (0), resulting in a maximum of 6 decimal places, using scientific 
notation when appropriate.


> print convert(money,12.345);     -- prints 12.35

Implicit conversion to varchar, using the default style setting for 
money/smallmoney (0 - no commas for thousands separators and 2 decimal 
places)


> print 12.35-convert(money,12.345);     -- prints 0.0050

Same as the first, with the wrinkle that arithmetic using money and real 
values results in a real value.

> print convert(money,12.35)-convert(money,12.345);     -- prints 0.01

Same as second - answer rounded to two places

> print 12.345+convert(money,12.345)-12.345;     -- prints 12.3450

Sane as third
>
>     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.
>
Look up the Style arguments for CONVERT() in BOL. This can all be avoided by 
using explicit conversions. 

Back to comp.databases.ms-sqlserver | Previous | NextPrevious in thread | Next 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