August 10, 2005 at 7:47 am
I need to truncate down (always round down) to 2 decimal place. The field is declared as money. For example:
200.2345 should be 200.23
200.2355 should be 200.23
Any use of the convert function does rounding.
The purpose is to calculate a per pay amount from a month amount and we have to give the benefit to the person (always rounding down).
Any suggestions?
I have searched on this and one posting around 7/8/2004 didn't seem to work in this case.
Thanks
August 10, 2005 at 8:01 am
August 10, 2005 at 8:04 am
Thanks, that worked.
August 10, 2005 at 8:11 am
Great
Perhaps you need to adjust the numbers so your max values will fit.
select substring(str(@m, 10, 4),1,8)
The 10 is max total length including all decimals and decimal points etc, the '8' should be 2 less than the number in '10' position.
/Kenneth
August 10, 2005 at 8:17 am
This the round seems to be much simpler and also works.
Thanks to all
August 10, 2005 at 8:35 am
yet another version:
declare @m as money
set @m = 200.2365
select floor((@m * 100)) / 100
results:
200.2300
Lowell
August 10, 2005 at 8:48 am
Gosh, I guess the phrase, "many ways to skin a cat" applies here. However, where did that phrase ever come from?
August 11, 2005 at 9:54 am
You usually don't want to use FLOOR, as this causes a conversion to float, which is an APPROXIMATE number. Stick with human-style math, like the ROUND with truncation mentioned in an earlier post.
August 11, 2005 at 10:41 am
are you sure about the floor function returning an approximate number? the BOL says it returns the integer portion of the value, and returns it as the same data type.
I always interpreted this say it truncated at the decimal point and returned a value of the same datatype....so are you saying it could potentially return an approximation of say 87.345 as 87.00000000000000001?
i couldn't find an example of this being true so far....
Lowell
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply