We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Round Money Field to 2 decimals

DJMoonLight
DJMoonLight asked
on
Medium Priority
712 Views
Last Modified: 2008-01-09
How do you round a money field to 2 decimals?

I would have thought rount(field, 2) would work but it doesn't

I only want to return:


Original Value = 12.040506  -----   Return Value =  12.04

Thanks
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2004

Commented:
What does yours return?  This should be the proper syntax:

round(myfield, 2)

Syntax
 
ROUND ( numeric_expression, length [ , function ] )
 

Arguments
numeric_expression
An expression of the exact numeric or approximate numeric data type categories, or types that are implicitly convertible to float.

length
The precision to which numeric_expression is to be rounded. When length is a positive number, numeric_expression is rounded to the number of decimal places specified by length. When length is a negative number, numeric_expression is rounded on the left side of the decimal point, as specified by length.

function
The type of operation to perform. When function is omitted or has a value of 0 (default), numeric_expression is rounded. When a value other than 0 is specified, numeric_expression is truncated.

Author

Commented:
Mine returns the number rounded to that many in the decimal..
For example:

17.701010 = 17.700000

 
I only want 17.70 returned

I think the round is working.  maybe you are assigning the result to a float or other numeric datatype.  You can do this instead of using round.

Declare @RoundValue decimal(18,2)

select @RoundValue = CAST([Original Value] as decimal(18,2))

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
AneeshDatabase Consultant
CERTIFIED EXPERT
Top Expert 2009

Commented:
CAST(round(myfield, 2) as Numeric(18,2))
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.