-1

I'm trying to get the first decimals of a float number without any kind of rounding.

Example:

var myfloat = 1.1864526;
myfloat = myfloat.toFixed(2);

It returns 1.19 but I need 1.18.

I'm pretty sure there is an easy solution but I am unable to find it without converting the number to a string (not useful in this case).

thefourtheye
  • 233,700
  • 52
  • 457
  • 497

1 Answers1

0

Multiply the float value by 100, get the int value of the result then divide that int by 100. Something like this should work:

((int)(myFloat*100)) / 100