JavaScript Calculator always rounding to floor -


i have made calculator of need it's rounding floor results.

how can make show exact results?

function tofixed(value, precision) { var precision = precision || 0,   neg = value < 0,   power = math.pow(10, precision),   value = math.round(value * power),   integral = string((neg ? math.ceil : math.floor)(value / power)),   fraction = string((neg ? -value : value) % power),   padding = new array(math.max(precision - fraction.length, 0) + 1).join('0');      return precision ? integral + '.' +   padding + fraction : integral; } function dosage () {    var =  parseint(jquery("#a").val() ) ;   var b =  parseint(jquery("#b").val() ) ;   var c =  parseint(jquery("#c").val() ) ;   var r = math.round(a*((a*(b/100)*2)+(c*25.4))*(0.0152/100));  r = tofixed(r,1); 

well, if wrote code, added:

 integral = string((neg ? math.ceil : math.floor)(value / power)) 

so, if don't want math.floor, should take out? or, if want math.floor, need investigate neg value causing return value rounded down.

the line, have seems incorrect second part:

 (value / power) 

is expression next result of ternary operation. i'm not sure how portion affecting anything.


Comments