Nano HE
Nano HE

Reputation: 1971

Trim double value in C++

How can I remove the uesless '0' for double value in C++?

double dVal = 6.606000;
double dOut;

dOut = someMethod(dVal); // dOut = 6.606;

thanks.

Upvotes: 0

Views: 622

Answers (1)

David Schwartz
David Schwartz

Reputation: 182819

Your question is based on a misunderstanding.

If you have 10 pencils or 10.0 pencils, the pencils are the same. There's no way to take 10.0 pencils and give back 10 pencils. -- They're the same pencils. In pencils, "10.0" and "10" are the same.

The zeroes are not in the stored value, they're just presented that way for output. The way "6.606000" is represented as a double is identical to the way "6.606" would be represented.

Upvotes: 4

Related Questions