vanilla JavaScript solution to check if number has no more than 6 digits and 2 decimal places -


i need return validation check (boolean) if number has no more 6 number of digits , no more 2 decimal places.

for example:

1 = valid 10 = valid 111111 = valid 111111.11 = valid 1111111.11 = invalid 1.111 = invalid 

looking through stack overflow can find answers input automatically rounded (not want) or decimal places have equal 2 decimal places (not @ 2).

obviously, need

function valid(n) {    return no_more_than_six_digits(n) && no_more_than_two_decimal_places(n); } 

so how define these functions?

function no_more_than_six_digits        (n) { return n < 1e7; } function no_more_than_two_decimal_places(n) { return math.floor(n * 100) === n * 100; } 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -