Test cases:
var num1 = 10.66;
var num2 = 10.7898
The function I found on stackOverFlow:
function formatUserCurrencyValue(fieldValue){
var num = parseFloat(fieldValue);
var str = num.toFixed(10);
str = str.substring(0, str.length-7);
return str;
};
I would like the result to be like this: if 10.66
then 10.670
and if 10.78998
then 10.789
. Basically if the value has 2 decimal places then the result should round up the first and then format as 3 decimals. If more than 2 decimals (eg. 10.78998
) then 10.789
, trimming out values after 3 decimals.
Could somebody please tell me how I can achieve this? I tried with the above function as well as some others I found but the result is not what I expected for the 10.66
scenario. I am getting 10.660
instead of 10.670
.