Allow 2 decimal places in

I have a <input type=”number”> and I want to restrict the input of the users to purely numbers or numbers with decimals up to 2 decimal places. Basically, I am asking for a price input. I wanted to avoid doing regex. Is there a way to do it? <input type=”number” required name=”price” min=”0″ value=”0″ step=”any”> … Read more

How to format a floating number to fixed width in Python

How do I format a floating number to a fixed width with the following requirements: Leading zero if n < 1 Add trailing decimal zero(s) to fill up fixed width Truncate decimal digits past fixed width Align all decimal points For example: % formatter something like ‘{:06}’ numbers = [23.23, 0.123334987, 1, 4.223, 9887.2] for … Read more