Groups | Blog | Home
all groups > visual c > march 2005 >

visual c : stream manipulator for set precision closing zeroes?


Peteroid
3/30/2005 10:05:13 PM
In the same spirit as setw( ) and setprecision( ), is there a stream
manipulator that will fill in closing-zeroes on those fractions with a given
setprecision( )?

For example, if setprecision(3) is used, I want '1' to be displayed as
"1.000", '1.2' to be displayed as "1.200", '1.23' to be displayed as
"1.230", '1.234' to be displayed as "1.234", and '1.2345' to be displayed as
"1.234" (or the rounded version "1.235" is ok too).

Thanx in advance!!!

[==Peteroid==]

Tom Widmer
3/31/2005 12:35:50 PM
[quoted text, click to view]

std::fixed and std::ios_base::fixed are what you want. e.g.

#include <iostream>
#include <iomanip>

int main()
{
std::cout << std::setprecision(3) << std::fixed
<< 1.23456 << ' ' << 1.2 << '\n';
}

Peteroid
4/1/2005 6:14:46 AM
Hi Tom,

Thanks! :)

[==Peteroid==]

[quoted text, click to view]

AddThis Social Bookmark Button