Wednesday, August 20, 2014

Using the SQL Round function with negative values

I had an issue where the Round finction was rounding the value '-19.395' as '-19.39'

The SQL statement was -

Select Round(((((Table.Value) * ISNULL(Table.Value, 1) * (-1))) - (Table.Value* 0.029)), 2) As Result

I was able to resolve the issue by 'casting' the value as a 'Money' data type.

Select Round(Cast(((((Table.Value) * ISNULL(Table.Value, 1) * (-1))) - (Table.Value * 0.029)) As Money), 2) As Result

With this, the value returned was '-19.40'

No comments:

Post a Comment