math - javascript equation resulting in -0 -
this question has answer here:
- is floating point math broken? 20 answers
i have javascript equation:
var sbal=pfweight-gweight-adjm; $("#result").html(sbal.tofixed(5));
if result 0, assign result css color green. if not 0, assign result css color red.
my problem math comes out -0 , displays red.
i tried
if(sbal===0){sbal=parseint(0);}
sbal===0 returns true.
how can work around this?
i know are +0 , -0 same? addresses why -0 = +0 not supply , answer on how fix problem.
if issue returns -0, can calculate absolute value of return value
math.abs(-0); // 0
edit: javascript has strange rounding of floating point numbers: if roundup result works fine, don't need math.abs(-0). pointed out -0 , 0 should same value.
this worked me:
var sbal = math.ceil(pfweight - gweight - adjm);
Comments
Post a Comment