I have the below JavaScript code to round the values, which returns different result in similar cases. This is being called through a tool.
var precision = -1;
/**
* Initialization
*/
function _init()
{
precision = 8;
}
case1
function RoundUp(number, num_digits)
{
var shift = Math.pow(10, num_digits);
var rounded = Math.ceil(number * shift) / shift;
rounded = (precision>-1) ? Number(rounded.toFixed(precision)) : rounded;
return rounded;
}
case2
function RoundUp(110, 1)
{
var shift = Math.pow(10, num_digits);
var rounded = Math.ceil(number * shift) / shift;
rounded = (precision>-1) ? Number(rounded.toFixed(precision)) : rounded;
return rounded;
}
If we directly pass some parameter values, ex (110,1), it returns 110. (CASE2) But when we pass the same parameter values indirectly through some variable (CASE1), the output changes to 111 for some reason.
Here, number = 110 and num_digits = 1
I cant figure out why this is the case. Can someone please help. Pardon me, but I am new to JavaScript.
Thanks
_init? Do you ever call it?