4

I am having some data calculation on my client side, which I want to validate on the server end. Let's say my calculated value result is 34.55

(34.55).toFixed(1) gives me 34.5

Strangely, (34.555).toFixed(1) gives me 34.6

number_format(34.55, 1, '.', '') gives me 34.6

Can anyone suggest me an exact equivalent of either of the functions?

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Annapurna
  • 529
  • 1
  • 6
  • 19

1 Answers1

1
round(1.95583, 2);  // 1.96

round( 1.55, 1, PHP_ROUND_HALF_DOWN); //  1.5

round( 1.54, 1, PHP_ROUND_HALF_DOWN); //  1.5

round( 1.55, 1, PHP_ROUND_HALF_EVEN); //  1.6

round( 1.54, 1, PHP_ROUND_HALF_EVEN); //  1.5

if you have any questions, ask

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
  • toFixed() is giving me inconsistent results. `555x0.029 = 16.095 --> (16.095).toFixed(2) returns 16.10` `5555x0.029 = 161.095 --> (161.095).toFixed(2) returns 161.09` – Annapurna Feb 21 '18 at 09:49