I've run into a bug within my PHP application that is really doing my head in.
When using number_format()
on a number, inside an HTML input (number) tag, the number doesn't show if it's higher than 1000! It does work, however, if I set the HTML input type to 'text'.
Observe the following code:
<input type='number' value="<?php echo number_format(1000,0); ?>" /><br /> <!-- displays nothing -->
<input type='text' value="<?php echo number_format(1000,0); ?>" /><br /> <!-- displays 1,000 -->
<input type='number' value="<?php echo number_format(500,0); ?>" /><br /> <!-- displays 500 -->
<input type='text' value="<?php echo number_format(500,0); ?>" /><br /> <!-- displays 500 -->
I found a "solution", by removing the 1000 separator:
number_format(1000,0,'.','')
...however for big numbers, I really need the 1000 separator for visibility.
Does anyone know a way of getting around this? I'm hitting my head in the wall here!
My fiddle: http://viper-7.com/vg3LyW
It's not possible to have a thousands separator with the native input field: https://www.ctrl.blog/entry/html5-input-number-localization.html
If you really need it, you have to use some kind of JavaScript replacement.