I would like to align numbers in a table. Usually it can be done with
<td aligh="char" char=".">
But some of my numbers do not have a decimal point (I would like do show 8 instead of 8.0000). These numbers will not be aligned correctly. Is there any possibility to do this without extensive use of javascript etc.?
CodePudding user response:
You wrote aligh
not align
, which could be why it's not working. We can't help without all of the affecting code.
CodePudding user response:
I don't know if you do not want to use JS at all but it would be easily fixed by casting like:
Number(5.17) => 5.17
Number(5.00) => 5
Number(5.50) => 5.5
even with strings:
Number('5.17') => 5.17
or you can parse:
parseFloat('17.00') => 17
parseInt('17.07') => 17 (removes .07)
parseFloat('17.07') => 17.07
You can also fix the number of decimals if it can help, using this:
Number((5.5644).toFixed(2)) => 5.56