Link to home
Start Free TrialLog in
Avatar of JElster
JElsterFlag for United States of America

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 ?
Avatar of Shaun Kline
Shaun Kline
Flag of United States of America image

The ROUND function would work.
ROUND(<value>, 2, 1)
ASKER CERTIFIED SOLUTION
Avatar of Shaun Kline
Shaun Kline
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JElster

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)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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).toFixed(2);

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.