Click to See Complete Forum and Search --> : converting 'values' to decimal with 0.0


gret
July 20th, 2005, 12:02 AM
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

exterminator
July 20th, 2005, 12:38 AM
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 (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdecimalclassroundtopic.asp). Hope this helps. :thumb:

Don't forget to rate good/helpful posts. :thumb:

Pinky98
July 20th, 2005, 12:48 AM
other wise, use the string's format method to acquire the correct effect.

gret
July 22nd, 2005, 10:14 PM
i see thanks to both

jmcilhinney
July 23rd, 2005, 05:47 AM
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.