Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^6: Change decimal point temporarily

by lima1 (Curate)
on Aug 03, 2010 at 00:32 UTC ( #852574=note: print w/ replies, xml ) Need Help??


in reply to Re^5: Change decimal point temporarily
in thread Change decimal point temporarily

Hm, It seems to work if you use locale:

perl -we 'use POSIX; use locale; setlocale LC_NUMERIC, "fr_FR"; $x = " +123,45"; $x+=0.1; print $x; setlocale LC_NUMERIC, ""; $x += 0.1; prin +t $x;'
Update: this does not work:
perl -we 'use POSIX; use locale; setlocale LC_NUMERIC, "fr_FR"; $x = " +123,45"; print $x; setlocale LC_NUMERIC, ""; $x += 0.1; print $x;'
So what I do now is to add 0 if it looks_like_number() and everything works fine. At least what I've tested until now...


Comment on Re^6: Change decimal point temporarily
Select or Download Code
Re^7: Change decimal point temporarily
by ikegami (Pope) on Aug 03, 2010 at 02:40 UTC

    ah! In that case,

    (my $tmp = $s) =~ s/,/./; $s = $tmp if looks_like_numbers($tmp);

    You'd be better of specifying which columns are numeric, though. Text::CSV_XS can even take advantage of that information if you tell it (via types).

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (14)
As of 2014-07-11 12:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (224 votes), past polls