Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MYSQL database Store Float Number as 00.00

I have a column in MYSQL database table called available_balance float(10,2), Its all fine but its storing value 0.00 instead of 00.00 or if 09.33 its storing 9.33. Instead I am looking for 09.33 to store, I can display 09.33 using PHP but since I have large data, I do not want process to convert numbers in PHP if mysql database with Float Column allow me to store number like 00.00 and 09.33 etc.
Let me know if anyone here can help me for solve the puzzle. Thanks!

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can display it with the format you need but not store it with float column type,
Use function LPAD() to show the numbers (left) padded with zeros:

select id, LPAD(available_balance,5,"0") from my_table

result

id      LPAD(available_balance,5,"0")
1       05.00
2       50.20
3       01.20
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading