473,773 Members | 2,277 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Formatting decimal places

I trying to format my output to display a set number of decimal
places. I have been trying to use the <iomanip> setprecision(), but
that will only display the total number of digits. Can someone please
help me???? Thanks.
Jul 22 '05
36 7828
Julie wrote:
Jeff Schwab wrote:
Julie wrote:
Jeff Schwab wrote:
Claudio Puviani wrote:
>"Jeff Schwab" <je******@comca st.net> wrote
>
>
>
>>Claudio Puviani wrote:
>>
>>
>>
>>>These libraries are NOT the core standard C++
>>>langua ge/libraries which is the topic of this newsgroup.
>>
>>Where is that topic stated?
>
>
>http://www.parashift.com/c++-faq-lit...t.html#faq-5.9
>
>"Only post to comp.lang.c++ if your question is about the C++ language itself.
>For example, C++ code design, syntax, style, rules, bugs, etc. Ultimately this
>means your question must be answerable by looking into the C++ language
>definiti on as determined by the ISO/ANSI C++ Standard document, and by planned
>extensio ns and adjustments."
>
>Clearly, this excludes third party libraries, unless they somehow made it into
>the ISO/ANSI C++ Standard document.

This excludes questions about thirdy-party libraries. IMO, it is in no
way OT to direct someone to an appropriate resource.
That last statement is true only if qualified:

...if there is no suitable implementation or construct in C++


Boost *is* a suitable implementation in C++.

I can't believe you still don't understand what I'm saying. I'll try to
clarify:

...if there is no suitable implementation in the standard C++ library or no
suitable construct in the native C++ language


And putting that construct in a namespace called "boost" makes it OT?
Jul 22 '05 #31
Jeff Schwab wrote:

Julie wrote:
Jeff Schwab wrote:
Julie wrote:

Jeff Schwab wrote:
>Claudio Puviani wrote:
>
>
>>"Jeff Schwab" <je******@comca st.net> wrote
>>
>>
>>
>>>Claudio Puviani wrote:
>>>
>>>
>>>
>>>>These libraries are NOT the core standard C++
>>>>langua ge/libraries which is the topic of this newsgroup.
>>>
>>>Where is that topic stated?
>>
>>
>>http://www.parashift.com/c++-faq-lit...t.html#faq-5.9
>>
>>"Only post to comp.lang.c++ if your question is about the C++ language itself.
>>For example, C++ code design, syntax, style, rules, bugs, etc. Ultimately this
>>means your question must be answerable by looking into the C++ language
>>definiti on as determined by the ISO/ANSI C++ Standard document, and by planned
>>extensio ns and adjustments."
>>
>>Clearly, this excludes third party libraries, unless they somehow made it into
>>the ISO/ANSI C++ Standard document.
>
>This excludes questions about thirdy-party libraries. IMO, it is in no
>way OT to direct someone to an appropriate resource.
That last statement is true only if qualified:

...if there is no suitable implementation or construct in C++

Boost *is* a suitable implementation in C++.

I can't believe you still don't understand what I'm saying. I'll try to
clarify:

...if there is no suitable implementation in the standard C++ library or no
suitable construct in the native C++ language


And putting that construct in a namespace called "boost" makes it OT?


I've already answered that numerous times. Just forget it.
Jul 22 '05 #32
Julie wrote:
>>>http://www.parashift.com/c++-faq-lit...t.html#faq-5.9
>>>
>>>"Only post to comp.lang.c++ if your question is about the C++ language itself.
>>>For example, C++ code design, syntax, style, rules, bugs, etc. Ultimately this
>>>means your question must be answerable by looking into the C++ language
>>>definiti on as determined by the ISO/ANSI C++ Standard document, and by planned
>>>extensio ns and adjustments."
>>>
>>>Clearl y, this excludes third party libraries, unless they somehow made it into
>>>the ISO/ANSI C++ Standard document.
>>
>>This excludes questions about thirdy-party libraries. IMO, it is in no
>>way OT to direct someone to an appropriate resource.
>
>
>That last statement is true only if qualified:
>
>...if there is no suitable implementation or construct in C++

Boost *is* a suitable implementation in C++.
I can't believe you still don't understand what I'm saying. I'll try to
clarify:

...if there is no suitable implementation in the standard C++ library or no
suitable construct in the native C++ language


And putting that construct in a namespace called "boost" makes it OT?

I've already answered that numerous times. Just forget it.


You certainly have not answered it. Sorry, you're not getting off that
easily. :)

Posting C++ code to answer a question is clearly on-topic in
comp.lang.c++. Sometimes, a solution involves more code than may be
posted comfortably, so it must be discussed in a more abstract way.
Mentioning an existing repository of C++ code is one way of having such
a discussion. In this case, neither the problem posed by the OP nor the
solution provided by Boost are platform-specific; both involve only
"pure," standard C++. The complaint you've made seems to be that the
actual code is not part of the C++ standard; I can't believe this really
is what you meant, since most of the code posted here is the original
work of individuals, not excerpted from the standard. So, it seems that
the exception (no pun) you've taken to Boost is simply that it has a
name. Had I posted the code directly here, instead of redirecting the
OP to a named body of code, would you still have claimed it off-topic?
I really would like to understand the distinction you've made, and
whether I've correctly assessed your opinion.
Jul 22 '05 #33
Jeff Schwab wrote:
I've already answered that numerous times. Just forget it.
You certainly have not answered it. Sorry, you're not getting off that
easily. :)


Getting off easy??? Look at the length of this inane thread, nothing easy
about it...
Posting C++ code to answer a question is clearly on-topic in
comp.lang.c++.
Agree.
Sometimes, a solution involves more code than may be
posted comfortably, so it must be discussed in a more abstract way.
Agree. However, if there is a less-involved and equally valid solution, then
that is what should be posted. If the more involved solution uses external
libraries, then that should be considered off-topic.
Mentioning an existing repository of C++ code is one way of having such
a discussion.
Absolutely, but it should be in the context of C++.

If someone asks about a string class, and a respondent simply states:

Look at MFC CString

that is off-topic because: there is a suitable implementation that is part of
C++.

However, that doesn't strictly mean that CString is off limits. An equally
legitimate response to the hypothetical string class question could be:

Look at the std::string class.

However, if you have some Windows-specific needs,
consider the MFC CString class because it
encapsulates a lot of XXX functionality that may
be more suitable over the std::string interface
and/or implementation. If you go that route, refer
to numerous windows-specific newsgroups for follow-up
questions.
In this case, neither the problem posed by the OP nor the
solution provided by Boost are platform-specific; both involve only
"pure," standard C++.
In and of itself, being platform-neutral does _not_ qualify something as being
on-topic in this forum. Consider OpenGL, platform-neutral, and off-topic.
The complaint you've made seems to be that the
actual code is not part of the C++ standard; I can't believe this really
is what you meant, since most of the code posted here is the original
work of individuals, not excerpted from the standard. So, it seems that
the exception (no pun) you've taken to Boost is simply that it has a
name. Had I posted the code directly here, instead of redirecting the
OP to a named body of code, would you still have claimed it off-topic?
I really would like to understand the distinction you've made, and
whether I've correctly assessed your opinion.


My 'complaint' was that the original respondent should have either posted about
std::fixed or not responded, as the OP question was about "trying to use the
<iomanip> setprecision()" , of which Boost doesn't immediately apply, and is
therefore off-topic.

I realize that my original response is splitting hairs, and has decomposed into
splitting atoms -- I don't have much more to add.
Jul 22 '05 #34
(warning: various paragraphs snipped)

Julie wrote:
Sometimes, a solution involves more code than may be
posted comfortably, so it must be discussed in a more abstract way.

Agree. However, if there is a less-involved and equally valid solution, then
that is what should be posted. If the more involved solution uses external
libraries, then that should be considered off-topic.


I disagree.
If someone asks about a string class, and a respondent simply states:

Look at MFC CString

that is off-topic because: there is a suitable implementation that is part of
C++.
No, that is OT because it is platform-specific.
However, that doesn't strictly mean that CString is off limits. An equally
legitimate response to the hypothetical string class question could be:

Look at the std::string class.

However, if you have some Windows-specific needs,
consider the MFC CString class because it
encapsulates a lot of XXX functionality that may
be more suitable over the std::string interface
and/or implementation. If you go that route, refer
to numerous windows-specific newsgroups for follow-up
questions.
To me, *that* discussion would seem borderline OT. I wouldn't actually
complain about it, because it's brief, tasteful, and explicit about its
platform-specific nature.
In this case, neither the problem posed by the OP nor the
solution provided by Boost are platform-specific; both involve only
"pure," standard C++.

In and of itself, being platform-neutral does _not_ qualify something as being
on-topic in this forum. Consider OpenGL, platform-neutral, and off-topic.


You think pointing someone to OpenGL would be off-topic? I again
disagree. An in-depth discussion of OpenGL would be OT, but simply
mentioning OpenGL would not be.
My 'complaint' was that the original respondent should have either posted about
std::fixed or not responded, as the OP question was about "trying to use the
<iomanip> setprecision()" , of which Boost doesn't immediately apply, and is
therefore off-topic.

I realize that my original response is splitting hairs, and has decomposed into
splitting atoms -- I don't have much more to add.


OK. Thanks for taking the time to explain your opinion. I guess we'll
agree to disagree on this one.
Jul 22 '05 #35
Jeff Schwab <je******@comca st.net> wrote in message news:<wt******* *************@c omcast.com>...

You guys do realize that you are having this discussion in a thread
entitled, "Formatting decimal places", right?

<mischievous grin>
Jul 22 '05 #36
Dave Moore wrote:
Jeff Schwab <je******@comca st.net> wrote in message news:<wt******* *************@c omcast.com>...

You guys do realize that you are having this discussion in a thread
entitled, "Formatting decimal places", right?

<mischievous grin>


The titles of threads about topicality rarely say "topicality ."

Anyway, I think the discussion has pretty much been concluded.
Jul 22 '05 #37

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

Similar topics

0
2706
by: ian | last post by:
Hi guys, i'm trying to format the output of a record in access, which i am pulling from through php (odbc) and the formatting is set at 4 decimal places, which i don't want. i want currency and no decimal places. I was trying to use this example, but i have no bloody idea howo to use it. or where to put it for that matter: <?php $number = 1234.56;
17
6150
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number. "Decimal Number" sometimes serves to distinguish Base 10 numbers, eg "15", from Base 2 numbers, Eg "1111". At other times "Decimal Number" serves to differentiate a number from an integer. For the rest of this post I shall only use either...
8
11331
by: nick | last post by:
printf("%lf",3.25); the result is 3.25000 i want the answer correct to 3 decimal places What should i do? thanks!
7
12700
by: Chris | last post by:
Where can I find a fairly comprehensive list of the formatting codes used when data binding. e.g. <%# Bind("Debit", "{0:C}") %>. Specifically formatting a number to 2 decimal places. Regards, Chris.
17
5285
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 places. The function accepts a compulsory first argument of type double (the number to be formatted) and a second optional argument of type integer (the number of decimal places) and returns a string object containing the formatted text. If the...
4
1807
by: sparks | last post by:
In this database some of the text boxes need to be/show something like 88.9. in the table I marked them single, format 00.0 and decimal places 1 on the form I have fixed and 1 if someone types in 88.9 its fine....if they type in 88.99 it gets displayed as 89.0 but in the table its 88.99 when you click on the value in the table. I wanted to do something like ##.# so they had to put in the correct
3
2504
by: Nathan Sokalski | last post by:
I am using databinding to populate a dropdownlist with numeric values. Some of the values have more decimal places than others, and I only want the minimal number of decimal places necessary displayed. The only way I have found to do this is to use the following for the DataTextFormatString property: "{0:0.######}" This displays what I want for now, but if the number had more that 6 decimal places, it would not work. Is there any way...
9
2323
by: john coltrane | last post by:
Is there way to create a formatted string in a similar that is similar to sprintf? The same for printing, printf? C,D,E,F,G,N,X for currency, decimal, exponential, fixed, general, numerical, and hex but these do not seem to allow for specifying the number of decimals, left/right placement, or string formatting. Thanks
2
11915
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 the information of a bunch of objects. The actual data is numeric. Since these reports are meant to be flexible number formatting must be configured as defined by the requirements. For example, sometimes the values will have to be rounded to 5...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10264
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8937
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6717
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4012
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.