Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 currency format.

Author  Topic 

shemayb
Posting Yak Master

159 Posts

Posted - 2008-02-21 : 22:11:07
Hi!

I have money value of 56.0000.I want it to only give me the last two decimal places,56.00.I used this one to come up to that result:cast(round(sum(total),2)as int)but my result is this 56.Am i on the right track?

Funnyfrog

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-02-21 : 22:16:31
Tried cast(round(sum(total),2)as decimal(18,2))?
Go to Top of Page

shemayb
Posting Yak Master

159 Posts

Posted - 2008-02-21 : 22:17:26
i haven't tried it..i will try it now..thanks!

Funnyfrog
Go to Top of Page

shemayb
Posting Yak Master

159 Posts

Posted - 2008-02-21 : 22:19:06
i tried it but it didn't work..

Funnyfrog
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-02-21 : 22:37:57
How about cast(sum(total) as decimal(18, 2))?
Go to Top of Page

shemayb
Posting Yak Master

159 Posts

Posted - 2008-02-21 : 22:52:49
i also tried that earlier,but still nothing happens.

Funnyfrog
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-02-21 : 22:54:46
Worked on my try.
Go to Top of Page

shemayb
Posting Yak Master

159 Posts

Posted - 2008-02-21 : 22:56:38
the datatype of my value is money..what could be the possible reason why it did't work in my try?

Funnyfrog
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-02-21 : 23:02:01
That's what I tested for.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-22 : 00:58:42
quote:
Originally posted by shemayb

the datatype of my value is money..what could be the possible reason why it did't work in my try?

Funnyfrog


Run this and see what you get

declare @m money
set @m=56
select @m
select cast(@m as decimal(12,2))

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

shemayb
Posting Yak Master

159 Posts

Posted - 2008-02-22 : 01:55:14
it still won't work..

Funnyfrog
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-22 : 03:25:07
quote:
Originally posted by shemayb

it still won't work..

Funnyfrog


Post the query you used

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2008-02-22 : 13:32:16
This maybe?
DECLARE @Foo MONEY

SET @Foo = $1231222.9897

SELECT CONVERT(VARCHAR(20), @Foo, 1)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-23 : 00:56:05
quote:
Originally posted by Lamprey

This maybe?
DECLARE @Foo MONEY

SET @Foo = $1231222.9897

SELECT CONVERT(VARCHAR(20), @Foo, 1)



declare @m money
set @m=$1231222.9897
select @m
select cast(@m as decimal(12,2))

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -