math - javascript equation resulting in -0 -


this question has answer here:

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?

jsfiddle

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

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -