0

How to keep two decimal places in rate?

double rate;

double pi = Math.PI;
rate = fuel / distance ;

Console.WriteLine("Your fuel consumption rate is " + rate * 100 + "lt" + "/100km");
Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
Ryantt
  • 15
  • 3

1 Answers1

-1

You can Display them as like the following, where Math.Round() will help you to store rounded decimal in rate

rate = Math.Round((fuel / distance),2);
Console.WriteLine("Your fuel consumption rate is {0} lt/100km", (rate * 100).ToString("#.##"));
sujith karivelil
  • 28,671
  • 6
  • 55
  • 88