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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.