0

I'm having the trouble of assigning decimal points, when i want to display the price of my product in the table in one of my php pages. Using number_format solves the problem when i want to display in the normal version, but when i want to display in a numeric array type, i don't know how to make the queried value into decimal points.

Any ideas? the data is stored as a float value, and the column price from menurecords is displayed as; how to input a decimal value here?

    echo "<td align='center'><font color='#FFFFFF'>".$row[2]."</font></td>";

1 Answer 1

1
select
    format(field, 2) as formatted
from
    table

Please take note that Format() returns a string, and the result will be with two decimal places (in the above example) - i.e. 10 will be formatted as 10.00.

OR you can also use

You want to use the TRUNCATE command.

http://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#function_truncate

TRUNCATE(0.166, 2) = 0.16

or

ROUND(0.166, 2) = 0.17

hope this will sure help you.

Sign up to request clarification or add additional context in comments.

2 Comments

thank you. but where do you think i should input this code on my php form?
Add it your SQL query if you want to get data from mysql with decimal point

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.