MySQL Forums
Forum List  »  Newbie

Re: Padding Zeros for a max of 20 digits
Posted by: Phillip Ward
Date: January 10, 2022 07:53AM


How can I right pad the number with Zeros to make sure it's always 20 digits?

Short answer - You shouldn't.

Numbers don't have fixed, leading zeroes. They're just numbers.

BTW, whilst you can add trailing zeroes to a numeric value, doing so results in a totally different, numeric value.

If you want the Character Representation of your numbers to include leading zeroes then yes, you can do that, but you should store such values in a column with a Character Data Type.
It's just not worth running the Risk of an "unexpected" Type Conversion messing up your value comparisons.

'1'                    != '00000000000000000001'
'1'                    != '10000000000000000000'
'00000000000000000001' != '10000000000000000000'

Regards, Phill W.

Options: ReplyQuote

Written By
Re: Padding Zeros for a max of 20 digits
January 10, 2022 07:53AM

Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.