473,387 Members | 1,621 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,387 software developers and data experts.

formatting floating-point-numbers

Hi

I need to format floating-point-numbers with exact 2 digits after decimal
point. I could use printf with "%.2f", but it don't use std::locale.

Any ideas?
--
Tommi Mäkitalo
Dr. Eckhardt + Partner GmbH
Jul 22 '05 #1
4 2668
"Tommi Mäkitalo" <t.*********@epgmbh.de> wrote...
I need to format floating-point-numbers with exact 2 digits after decimal
point. I could use printf with "%.2f", but it don't use std::locale.

Any ideas?


Take a look at 'fixed' and other field flags from <ios>. They do
not use 'locale', IIRC.

V
Jul 22 '05 #2

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:UIpYb.48734$jk2.116305@attbi_s53...
"Tommi Mäkitalo" <t.*********@epgmbh.de> wrote...
I need to format floating-point-numbers with exact 2 digits after decimal point. I could use printf with "%.2f", but it don't use std::locale.

Any ideas?


Take a look at 'fixed' and other field flags from <ios>. They do
not use 'locale', IIRC.


Anybody have any idea why the std has support (or at least hooks) for
formatting money in a
locale dependent way and yet has no class that makes use of it?
Jul 22 '05 #3
Tommi Mäkitalo wrote:
Hi

I need to format floating-point-numbers with exact 2 digits after decimal
point. I could use printf with "%.2f", but it don't use std::locale.

Any ideas?


Just use:

std::cout << std::fixed;
std::cout.precision(2);

or if you like manipulators as I do, #include <iomanip> and use:

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

Alberto
Jul 22 '05 #4
"Nick Hounsome" <nh***@blueyonder.co.uk> wrote in message news:<6i***************@news-binary.blueyonder.co.uk>...
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:UIpYb.48734$jk2.116305@attbi_s53...
"Tommi Mäkitalo" <t.*********@epgmbh.de> wrote...
I need to format floating-point-numbers with exact 2 digits after decimal point. I could use printf with "%.2f", but it don't use std::locale.

Any ideas?


Take a look at 'fixed' and other field flags from <ios>. They do
not use 'locale', IIRC.


Anybody have any idea why the std has support (or at least hooks) for
formatting money in a
locale dependent way and yet has no class that makes use of it?


It's the same in C...LC_MONETARY was provided for choosing specific
monetary formats with setlocale(), then you could use localconv() to
get the currency_symbol etc. etc. But you had to do all the work
yourself, including grouping, decimal point selection (if different to
decimal point for non-monetry selection) etc. etc. It would seem
obvious enough to have printf-support printing monetary values, or
indeed formatting according to locale-conventions, and even proper
parsing (only the decimal point specifier is actually used by
atof/strtod - you can't use thousands grouping or different sign
formats). Of course there is strfmon, but no part of standard C, only
POSIX (I believe).

Dylan
Jul 22 '05 #5

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

Similar topics

1
by: George Hester | last post by:
At the time this suggestion was made I didn't have the wherewithall to even attempt it. But over time I learned enough to make a stab at it. Let just say the foating DIV had to provide the same...
2
by: Victor Bien | last post by:
W3C says somewhere that tables should not be used for formatting columns etc. but that style sheets should be used instead. This has a major unlearning/relearning implications for me (and just...
6
by: Timo | last post by:
I have this list of checkboxes displaying properly in Opera and IE, but cannot get it in Firefox. For some reason, in FF, the checkboxes creep farther and farther to the right across the page,...
22
by: KsAdmin | last post by:
I have a question which has had me stumped for a few days now. I have a form that I add the values of fields together and display the total in a total field. I have the calculations working...
3
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be...
2
by: Colleyville Alan | last post by:
I am using Access and have embedded the ActiveX control Formula One that came with Office 2000. (ver 3.04). I have created and formatted a spreadsheet and now I want to copy the info with...
11
by: hg | last post by:
Hi, Considering the float 0.0, I would like to print 00.00. I tried '%02.02f' % 0.0 ... but I get 0.00 Any clue ? Thanks,
1
by: Wayne Deleersnyder | last post by:
Hi All, I was going to write and ask if someone could help me fix the formatting of my output for hash values, but I believe I got it right now. But, because I couldn't find any website or...
9
by: Odysseus | last post by:
Hello, group: I've just begun some introductory tutorials in Python. Taking off from the "word play" exercise at <http://www.greenteapress.com/thinkpython/html/book010.html#toc96> I've written...
6
by: Jeremy | last post by:
I've got a floating div which becomes visible when a link is clicked. I want the div to be hidden when the user clicks anywhere on the page except for whithin the div. What is the best way to do...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.