I store money values in my db table. E.g. I have 2.50. But when I print that value the 0 is always missing so I get 2.5. The db table money field has the following type: decimal(6,2)
any idea how to fix that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
By default PHP
echoandprintdon’t print the trailing zeros of a floating point number.To overcome this you need to use
printfas:The format specifier used in
printfis"%.2f"what it means is always print atleast two digits after the decimal point and if there are not so many digits use0.Note that it is atleast two digits not equal to two digits. So if I print
1.234with that format it will not truncate it to1.23but will print1.234and if I print1it will result in1.00