|
| ||||||||||
| Tags: c language, c programmer, printf, scanf |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| ||||
| ||||
| Problem of Decimal point in C
|
|
#2
| ||||
| ||||
| Re: Problem of Decimal point in C
So just a very simple trouble this problem will be solved if you use %2f in the printf function. That means your code will become printf("%2f",n1). This function of the printf commands the C compiler to output the values only upto decimal places. that is only 12.34 will be the out put as required by you. |
|
#3
| ||||
| ||||
| Re: Problem of Decimal point in C
I mean when i am calling printf("%2f",n1) it will get 12.34, since the value in num is still 12.340000 it does not help me i would be happy if anybody tell me how can i change the value of n1 to 12.34 |
|
#4
| ||||
| ||||
| Re: Problem of Decimal point in C
Try to use double instead of float or if you want to avoid the accumulation of errors that float and double cannot represent every real number rearrange the order of certain operations use decimal math library or move to some other programming language that has a decimal type. if you want to try some other way read a string from the user using the fgets(), then convert the input to what called a scaled integer value. Now, you'll have to occasionally convert to double or float for some operations and then back again .
__________________ The FIFA Manager 2009 PC Game |
|
#5
| ||||
| ||||
| Re: Problem of Decimal point in C
Can you just tell me how many discrete values 32 bits or 64 bits can represents. Then think is it possible that same number of bits can represent values a thousand times as large. The answer is that it lumps a lot of values together under oa single number. |
|
#6
| ||||
| ||||
| Re: Problem of Decimal point in C
As far as i know the 12.34 value is same as 12.34 . Also i am very surprised to know %f would output trailing zeroes. which it avoids normally. Either the stored value is 12.340001 instead of 12.340000, Since by default %f always displays upto six decimal places only. And in your program if it displays such unusual . Then before giving you the solution you please specify me the type of compiler you are using. try to View the variable in your debugger to see all significant digits. |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Problem of Decimal point in C" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Stucked beween Decimal point and common issue in Microsoft Excel | Aza | MS Office Support | 3 | 21-02-2012 12:18 PM |
| How to remove the decimal point for cell in Microsoft Excel | Kungfu Pandey | MS Office Support | 1 | 14-01-2012 05:20 PM |
| VLC 1.1.7/openSUSE 11.3 having Floating point exception problem | Bryant | Windows Software | 6 | 12-07-2011 11:14 AM |
| Excel Issue for decimal Point | Bassus | Windows Software | 3 | 15-01-2009 09:54 AM |
| Wireless Access Point Router problem in Windows | Aatbodh | Networking & Security | 3 | 22-11-2008 04:39 PM |