| You are here: | About>Computing & Technology>C / C++ / C#> C> C Tutorials> All about Precision in Floats |
![]() | C / C++ / C# |
Elsewhere on the WebC Tutorial Lesson Two - Handling NumbersPrecision ArithmeticDouble TroubleThere's no long float, but there is a double type that is twice as big as float.
PrecisionConsider 567.8976523. It appears a valid float value. But if we print it out with this code below you can see lack of precision appearing. The number has 10 digits but is being stored in a float variable with only six digits of precision.
float value= 567.8976523; The function printf() outputs text to the screen. We'll look at it in detail later on in this lesson. It prints as 567.897644042969. Quite a difference! Now move the decimal point two to the left so the value is 5.678976523 and rerun the program. This time it outputs 5.67897653579712. This is more accurate but still different. If you count the digits that are the same in both sets of numbers, you can see that after 7 or 8 digits, the numbers differ. I've added a space and padded with 0s to highlight the differences.
Rerun both examples as doubles and it will print both exactly as defined. On the next page : Learn about computer Arithmetic.
Elsewhere on the Web |
Las Vegas on a BudgetFind a BargainHotel DealsCheap EatsFree AttractionsEntertainment for Less |
All Topics | Email Article | Print this Page | | ![]() |
| Advertising Info | News & Events | Work at About | SiteMap | Reprints | Help | Our Story | Be a Guide |
| User Agreement | Ethics Policy | Patent Info. | Privacy Policy | ©2008 About, Inc., A part of The New York Times Company. All rights reserved. |


