PDA

View Full Version : Round to whole number



9./JG52 Hans Gruber
May-20-2014, 20:05
In the following code how could I display a whole number only on the LogServer message? It works fine for kg bombs, displays a nice whole number. But 250/500 lb bombs display long decimals (i.e 102.3468694021).


AirfieldTargetsDamage[ap] = AirfieldTargetsDamage[ap] + mass;
string sPercentDamage = null;
double dPercentDamage = (AirfieldTargetsDamage[ap] / AirfieldTargets[ap] * 100);
sPercentDamage = dPercentDamage.ToString("0");
GamePlay.gpHUDLogCenter(AirfieldTargetsName[ap] + " is " + sPercentDamage + "% destroyed");
GamePlay.gpLogServer(null, AirfieldTargetsName[ap] + " is hit with " + AirfieldTargetsDamage[ap] + "kg of bombs", new object[] { });

SoW Reddog
May-21-2014, 05:58
Do you want to round up, or down, or to nearest whole number?

Google "c# round" and then the answer to the above question and you'll get lots of hits. https://www.google.co.uk/#q=c%23+round

ATAG_Colander
May-21-2014, 10:55
Or you can just cast it to int:

((int)AirfieldTargetsDamage[ap])

9./JG52 Hans Gruber
May-21-2014, 21:49
Or you can just cast it to int:

((int)AirfieldTargetsDamage[ap])

Perfect. Thanks!