0

So I'm having a problem of getting decimals. I can use them but when I do a calculation, that does not work. There's a lot of things to fix but is there any property that can help me?

let rank = prompt('Rank?', ''); // 2000
    let x = prompt ('Value of x?', ''); // 90
    let y = prompt ('Value of y?', ''); //1.6
    var a = parseInt(rank); // 2000
    var b = parseInt(x); // 90
    var c = parseInt(y); // 1.6
    var d = ((2000 - (500 * (3 - c)))/1000); // I get '1' instead of '1.3'
    var e = d*b; // I get '90' instead of '117' (1.3*90)
    var f = e*(y*y); // 334.0000004 (2*117) instead of 299.52 (2.56*117)
    var g = b*(1-c); // 0 (90*(1-1)) instead of -54 (90*(1-1.6))
    var h = a/90; // 22.2 is correct (2000/90)
    var i = 2-c; // 0 because it rounds 1.6 to 2 (should be 0.4)
    var j = h*i; // 0 and it should be 22.2*0.4

I just want to get rounded numbers in decimal part like 22.22222 becomes 22.2.

JustAsking
  • 27
  • 4

1 Answers1

3

you want parseFloat, not parseInt

toFixed(1); // if you want rounded to 1 decimal place

Rick
  • 1,710
  • 8
  • 17