Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: floating point validation

by aquarium (Curate)
on Aug 31, 2010 at 00:40 UTC ( [id://858103]=note: print w/replies, xml ) Need Help??


in reply to floating point validation

to get something more generic that is further extensible or easily changed, write a function that produces a (contrived) format of the input as its output. then you can easily change the truth conditional to fit purposes of the day.
first check that it's a number by adding zero and testing it still equals original input/number. then decide whether you need signed or not, with or without thousands separator, scientific notation, etc. i assume most of these can be excluded, apart from "not a number" result. then convert all digits and the decimal point to something like d->5->2 or similar, this return value scheme meaning the result is a number (the d), with 5 digits, and decimal point (if any) after second digit. a "not a number" result encoding could be something like "x" or "a" instead of "d". anyway, some form of easily parsable return code of this or similar kind is then easily tested for any preference of conditional, e.g. only want d->4->2 as per the example presented. hope it makes sense.
the hardest line to type correctly is: stty erase ^H

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://858103]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (10)
As of 2024-04-23 08:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found