|
-
July 20th, 2005, 12:02 AM
#1
converting 'values' to decimal with 0.0
how do you convert any value int, double, float and so on into a decimal with only .0 decimal place
example
height 155.55
height2 213.5
height3 444.0
average height = 271.0166666666=(height+2+3)/3
but i want to display only 271.0
-
July 20th, 2005, 12:38 AM
#2
Re: converting 'values' to decimal with 0.0
There is a Round method in the Decimal structure (but you would not find any equivalent method for double types) . It rounds the decimal variable to the specified number of decimal places. For examples and more detail see here. Hope this helps.
Don't forget to rate good/helpful posts.
Can you help me with my homework assignment?, Before you post!, Use code tags, How to post!, Codeguru technical FAQs, C++ FAQ Lite, Stroustrup: C++ Style and Technique FAQ, Guru of the Week, Comeau C and C++ FAQs, Comeau C++ Templates FAQs, CUJ @ DDJ, Spam threshold
My Blogs : Learning C++ is fun | Abnegator's reflections
Open Threads : C++ Aha! Moments | Nature of work in C++?
-
July 20th, 2005, 12:48 AM
#3
Re: converting 'values' to decimal with 0.0
other wise, use the string's format method to acquire the correct effect.
Mike
-
July 22nd, 2005, 10:14 PM
#4
Re: converting 'values' to decimal with 0.0
-
July 23rd, 2005, 05:47 AM
#5
Re: converting 'values' to decimal with 0.0
You can display any number as a string with exactly 1 decimal place by calling ToString("n1"). This will display 1 decimal place even if the number is a round integer. It will also perform standard rounding on the second decimal place. It further has the advantage of affecting display only and not the actual numerical value of the variable.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|