473,405 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

number of decimal places

Hi,

Is there any way to output a double value with different number of
decimal places (apart from using 'sprintf'). I looked up the reference
for C++ streams and found the 'setprecision' manipulator, but this sets
the number of digits before and after the decimal point. I can't seem
to find any manipulator for setting the number of digits after the
decimal point.

Thanks,
-shez-

Jul 22 '05 #1
3 1962
Sorry guys, i've found the answer. Pls ignore.

Sorry,
-shez-

Jul 22 '05 #2
On 19 Jan 2005 19:11:42 -0800, shez <sh************@gmail.com> wrote:
Sorry guys, i've found the answer. Pls ignore.


you would not need to be sorry, if you were so kind to post the answer you
have found - perhaps others are interested, too.

ps: ignoring, as you suggest, is not possible, because to do so, anybody
must read your original posting, plus your answer to it...

--
have a nice day
ulrich
Jul 22 '05 #3
> you would not need to be sorry, if you were so kind to post the
answer you
have found - perhaps others are interested, too.


You can use the 'std::fixed' manipulator before setprecision, like
this:

std::cout << std::fixed << std::setprecision(2) << 1.2345678 <<
std::endl;

This should print to two decimal places. Thanks, -shez-

Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Gizmo | last post by:
Hi there i was wondering if any one new to a function that rounds up a float to so many decimal places. I have a number in bytes and converting it to mb's and gb's but once its converted i need to...
6
by: John Bentley | last post by:
John Bentley writes at this level: If we think about our savings accounts then division never comes in (as far as I can see). We deposit and withdraw exact amounts most of the time. Occasionaly...
3
by: android | last post by:
I require a function that takes a double as a parameter and returns the number of decimal places. What is the most efficient way in c# to find out the number of decimal places I have written a...
5
by: Edward Hartfield | last post by:
I'm am relatively new to Python but use it daily. Today, I went looking for a function, like PHP's number_function, that will take a number and return a string with number formatted with grouped...
6
by: Hal Rosser | last post by:
From previous postings, I assume that the round method of the Math object leaves too much to chance, and should not be used. It has also been suggested that rounding be done by converting the...
6
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
19
by: VK | last post by:
http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/ b495b4898808fde0> is more than one month old - this may pose problem for posting over some news servers. This is why I'm...
17
by: scan87 | last post by:
Can somone please, please give me the solution for the following problem. I need to submit it on Monday. Write a global function called format, which formats numbers with a given number of decimal...
2
Pittaman
by: Pittaman | last post by:
Hello I am creating some crystal reports (for visual studio 2005) based on the content of certain .NET objects. I'm doing this in .NET 2.0. For one of them I'm using a Cross-table to summarize...
4
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I format a Number as a String with exactly 2 decimal places?...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.