-1

I am using the toFixed() method with 4 numbers directly, not using varibales to hold the numbers. The code doesn't run. It is curious because depending on what numbers I write the code run or doesn't.

<script>

document.write (-5.toFixed(2) + "<br><br>");

document.write (-3.286.toFixed(2) + "<br><br>");

document.write (55.3.toFixed(2) + "<br><br>");

document.write (226.32578.toFixed(2) + "<br><br>");

</script>

does anyone know why sometimes it runs and sometimes not depending on the numbers you enter?

Thanks

Israel
  • 25
  • 6
  • The problem is because you are using a `dot` after the integer in the first line, you can round it over a parenthesis that should work: `(-5).toFixed(2)` – intmarinoreturn0 Nov 16 '22 at 17:10

1 Answers1

0

you didn't mention which are working and which are not working, but writing your code like this would probably make everything work well:

document.write ((-5).toFixed(2).toString() + "<br><br>");    
document.write ((-3.286).toFixed(2).toString() + "<br><br>");    
document.write ((55.3).toFixed(2).toString() + "<br><br>");
document.write ((226.32578).toFixed(2).toString() + "<br><br>");
Rick
  • 1,710
  • 8
  • 17