JElster
asked on
Trim decimal places from Varchar field
Hi.. I have varchar field with values like this
00.1231556
123.99999999
56.12344455
Only need to 2 decimal place
00.12
123.99
56.123
what's the syntax ?
00.1231556
123.99999999
56.12344455
Only need to 2 decimal place
00.12
123.99
56.123
what's the syntax ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Error converting data type varchar to float.
Another option would be to use CHARINDEX to find the position of the period, add 2 to that value and then use LEFT:
LEFT(<value>, CHARINDEX('.', <value>) + 2)
LEFT(<value>, CHARINDEX('.', <value>) + 2)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
As you have posted this in javascript, I assume you want the javascript to pre-format for you and the code for that is:
var twoPlacedFloat = parseFloat(yourString).toF ixed(2);
Cd&
var twoPlacedFloat = parseFloat(yourString).toF
Cd&
Based on the error you posted, I'm guessing you have non-numeric data (maybe empty strings or NULLs) in that field as well. You can use the ISNUMERIC function to filter out records that does not contain numbers in your field.
ROUND(<value>, 2, 1)