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


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

Re: SSE2008 money Type

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail
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 Thu, 11 Oct 2012 11:16:30 +0000 (UTC)
Organization Erland Sommarskog
Lines 32
Message-ID <XnsA0E9870A87B52Yazorman@127.0.0.1> (permalink)
References <mqcc78906k2avdq0uuj25nem4r5b4qnsnp@4ax.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
Injection-Date Thu, 11 Oct 2012 11:16:30 +0000 (UTC)
Injection-Info mx04.eternal-september.org; posting-host="1bbf89cf6d97a98086f02eab6f51f760"; logging-data="14073"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19wrAFQSB9vNaPW+90eJ67U"
User-Agent Xnews/2005.10.03 Mime-proxy/1.4.c.4 (Win32)
Cancel-Lock sha1:72h1C+4xB0H0HwJNlKK+qBFP9Q8=
Xref csiph.com comp.databases.ms-sqlserver:1332

Cross-posted to 2 groups.

Followups directed to: comp.databases.ms-sqlserver

Show key headers only | 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