+ 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

12th Nov 2021, 3:23 PM
Andrius Savčiukas
8 Réponses
+ 4
Math.Round(density); //for rounding Math.Ceiling(density); //for round up or ceiling.
12th Nov 2021, 3:32 PM
Jayakrishna 🇮🇳
+ 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
12th Nov 2021, 3:55 PM
Lothar
Lothar - avatar
+ 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?
12th Nov 2021, 3:45 PM
Jayakrishna 🇮🇳
+ 1
And where do you write it?Jayakrishna🇮🇳
12th Nov 2021, 3:36 PM
Andrius Savčiukas
+ 1
Thanks
12th Nov 2021, 3:46 PM
Andrius Savčiukas
+ 1
Math.Round(density,n); Where n denotes number of places to round. Math.Round(density,2); for 2 places
12th Nov 2021, 4:08 PM
Jayakrishna 🇮🇳
0
But how do I make it round up to 2 numbers after the decimals?Jayakrishna🇮🇳
12th Nov 2021, 3:48 PM
Andrius Savčiukas