Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: DBI Removing Leading Zeroes 0's

by kennethk (Abbot)
on Apr 08, 2013 at 16:25 UTC ( [id://1027556]=note: print w/replies, xml ) Need Help??


in reply to DBI Removing Leading Zeroes 0's

To expound upon Corion's wisdom, you are conflating numerical values and formatting. As far as your database (as well as Perl) is concerned, 0301 and 301 are the same number, but are different strings. Oracle will also truncate trailing zeroes in decimals, because those contain no numerical information.

So the question is do you need to store all four digits, which would suggest you should use perhaps a char(4) type instead, or do you just need to output four digits? Any time you need to control formatting on a numerical output, you should probably turn to printf/sprintf, e.g.

~$ perl -e 'printf "%04d\n", 301' 0301

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2024-03-19 11:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found