Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am fetching data from MySQL using PHP. I know that most values stored in the database are float. Sometimes, the database outputs values like 3.9999E-5 and sometimes like 0.00104961904762 (14 digits).

How can I truncate the value to 8 digits only. I am currently using:

<? echo sprintf("%.8f",$get_results['Price']);?>
share|improve this question
I think this question is more suitable for – mustaccio Feb 12 '14 at 19:45
Stackoverflow doesn't allow me to post question even though I have 70+ reputation and many badges – Khan Shahrukh Feb 12 '14 at 20:08
What datatype are you using to store the numbers? – Colin 't Hart Feb 12 '14 at 22:44
I am using text as data type – Khan Shahrukh Feb 13 '14 at 3:48
You have already posted two questions at stackoverflow. So why do you think that you are not allowd to post questions at stackoverflow? – miracle173 Mar 15 '14 at 7:07

You need MySQL's FORMAT function

To round 0.00000123456 to 8 places, run the following within PHP:

mysql> select FORMAT(0.00000123456,8);
| FORMAT(0.00000123456,8) |
| 0.00000123              |
1 row in set (0.00 sec)


Give it a Try !!!

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.