You must Sign In to post a response.
  • Category: JavaScript

    Float values Substraction gives negative results in javascript

    I try to substract two variable like as

    var a = 3602.72238;
    var b =2597;

    var c = a - b;
    it gives negative the answer c =-1005.72238

    I want to positive answer like 1005.72238
    Whats wrong how rid of minus.

    Plz advice
    Thanks and regards
  • #769538
    Hi Brite,

    Try the below code,
    var c = parseFloat(a) - parseFloat(b);

    V.M. Damodharan
    "Your talent will be worthless, when you have fear and tension."

  • #769672
    There is no wrong in the above mentioned statements like
    var c = a-b;

    definitely it give's the expected value i.e 1005.72238, i feel you might have mentioned c = b-a instead of c= a-b hence it gives you negative value

    if still gets problem let me know on which browser are you referring this problem

    B.Ramana Reddy

  • Sign In to post your comments