![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Feb 2008
Posts: 1
Rep Power: 0
![]() |
limiting decimal places
Can some one give me an idea of how to limit decimal spaces from a double.
|
|
|
|
|
|
#2 |
|
Programmer
Join Date: Feb 2006
Location: Ohio
Posts: 93
Rep Power: 3
![]() |
Re: limiting decimal places
aShoe, if you're using the iostream library for output, you need to use the setprecision() manipulator (http://cppreference.com/io_flags.html#manipulators).
Example: #include <iostream> #include <iomanip> //... float floatval = 4.026783; std::cout << std::dec << std::setprecision(3) << floatval << std::endl; // outputs "4.03" Or, if you're using C style output: #include <stdio.h>
//...
float floatval = 4.026783;
printf("%.2f\n", nfloat);
// outputs "4.03"
__________________
Neeley.org |
|
|
|
|
|
#3 |
|
PFO God In Training
![]() Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 530
Rep Power: 4
![]() |
Re: limiting decimal places
You can only limit them on output, such as with cout of another output stream
double x = 12.1234567890; cout << setprecision(4) << width(4) << x << "\n"; has the following output 12.12 Press any key to continue . . . [edit] I was too slow. what dr.p said[/edit] |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| can anybody help me about conversion decimal to binary and vice versa.. | crigie | Assembly | 1 | Jan 11th, 2008 7:43 PM |
| Decimal to binary help | gam3r | Java | 20 | Nov 21st, 2007 8:57 PM |
| Java code to convert binary to decimal and hexadecimal to binary | prince_haldir | Java | 1 | Mar 7th, 2006 1:51 AM |
| Decimal conventions | JoeAvery | Delphi | 1 | Jan 18th, 2006 3:43 PM |
| hex and decimal RGB transforming please help | cloud- | Visual Basic | 5 | Jan 17th, 2005 3:17 PM |