[SOLVED] [php]sprintf issue that I don't understand
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
It is the same in C.
Maybe not what you expected, but it is also scientifically correct. If you specify the precision of a number in 2 decimals, the number has an uncertainty of 0.005.
Which means:
100.00 can be: 99.995 < value < 100.005 (which 99.9961.... is) This is scientifically correct.
If your output would have been 99.99, the original number could have been: 99.985 < value < 99.995 which is not correct.
So the precision specifier does exactly what the name says: it specifies the precision, not the number of decimal places. Yes, many text writers cut some corners and say it is the number of decimal places. If that were true, 99.9961... would be displayed as 99.99. But is does not correctly reflect the value that you measured.
(On a side note: it is therefore nonsense for a digital multimeter to display 1.534 as battery voltage if the meter has 1% accuracy)
If your display is 100.00, you can be sure the availability was > 99.995%. If you want to show that it was less than 100%, you have to use a higher precision.
I know it's mathematically correct, but did not expect it. As a programmer I want it mathematically correct, as a user I don't expect to see an uptime of 100% if there was the smallest amount of downtime. I will talk to the customer (again).
And I indeed used a floor to solve the issue.
Thanks again
Last edited by Wim Sturkenboom; 01-15-2009 at 11:04 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.