If Decimal Value, Convert To Two Decimals And Dot Separated Value To Comma Separated
I currently have values that look like the following: 30 32.5 How can I convert these to have two decimals if there is any decimals present (like the 2nd example), AND have the do
Solution 1:
Try,
var num = 32.5;
num = num.toFixed(2).split('.').join();
DEMO
var num = 32;
num = (num.toString().indexOf('.') > -1) ? num.toFixed(2).toString().split('.').join() : num;
DEMO
Solution 2:
var num = 32.5;
num = (num % 1 != 0) ? num.toFixed(2).toString().replace(".", ",") : num;
Post a Comment for "If Decimal Value, Convert To Two Decimals And Dot Separated Value To Comma Separated"