+ 4
Question
How to make the answer round up to like 2, 3 and etc. numbers after the decimal in c#? I would appreciate if you could show me where and how to write it in my mini project: https://code.sololearn.com/cp59qscCbHk6/?ref=app
8 Answers
+ 4
Math.Round(density); //for rounding
Math.Ceiling(density); //for round up or ceiling.
+ 5
Andrius Savčiukas ,
to round to 2 decimal places we can use:
Console.WriteLine(Math.Round(4.412761, 2));
the last argument in Round() function defines the decimal places to round
+ 2
Where ever you want...!
Ex:
Console.WriteLine("When your mass is "+mass+" and volume is "+volume+" density = "+Math.Ceiling(density)+" kg/m^2 or "+Math.Ceiling(density/10)+ " g/cm^2");
Andrius Savčiukas
what is the expected output in your code?
+ 1
And where do you write it?Jayakrishna🇮🇳
+ 1
Thanks
+ 1
Math.Round(density,n);
Where n denotes number of places to round.
Math.Round(density,2); for 2 places
0
But how do I make it round up to 2 numbers after the decimals?Jayakrishna🇮🇳