skip to Main Content

I have variable result. It contains each time different value. It is decimal number. How can i round or just show 3 decimal places?

Code:

var result = amount * exchangeRate1[fromCurrency] / exchangeRate2[toCurrency];

2

Answers


  1. Try this:

    Math.Round(result, 3);
    
    Login or Signup to reply.
  2. if you want to SHOW 3 decimal places, you have to format value to string

     string val = Math.Round(result,3).ToString("0.000"); // 2.000
    

    if you use just Round

    result = Math.Round(result,3) // 2
    

    it will be shown less then 3 decimal places, if your result has less than 3 decimal places.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search