Replies: 1 comment
-
I proposed number or decimal to |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
It’s relatively easy to turn a float into a number with a fixed set of decimals, but these decimals are always rounded. 4.445 will become 4.45 for example, which isn't always what you want.
This means that if you want to explicitly do a
floor
or aceil
, you have to resort to something like thisAnd neither of these is a particularly clear bit of JavaScript.
If
toFixed()
took an optional second argument—perhaps an object, for future extensibility—that would empower developers to choose an existing function or supply their own function to use in rounding the number, which would create a much nicer (and self-documenting) experience:The custom function could receive either the original number and the number of decimals, or get a float that needs to be rounded to an int. It can then convert that to a string with the proper number of decimals.
https://webwewant.fyi/wants/2e197cac8499acaf81c38cfb210fd3c29dd2a8fd/
Beta Was this translation helpful? Give feedback.
All reactions