Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 662
  • Last Modified:

Round Money Field to 2 decimals

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
0
DJMoonLight
Asked:
DJMoonLight
1 Solution
 
Steve BinkCommented:
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.

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

17.701010 = 17.700000

 
I only want 17.70 returned

0
 
DonKronosCommented:
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))

0
 
Aneesh RetnakaranDatabase AdministratorCommented:
CAST(round(myfield, 2) as Numeric(18,2))
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now