Search code examples
c#doubledecimalroundingambiguous

Ambiguous call Math.Round ( int64 / int64, int)


I would like to do percentage with large number (int64 : 600 851 475 143)

My actual operation is

a = Math.round(i / 600851475143 * 100, 5);

With i also an int64 between 1 and 600851475143. The result will be between 0,00000% and 100,00000% if i'm right.

But Visual Studio Express 2013 say me that ambiguous call between methods 'System.Math.Round(decimal, int)' and 'System.Math.Round(double, int)'.

How to say to visual that the good methods is System.Math.Round(decimal, int) even if some int64 are in the operation ?

Bonus : To understand my problem, i'm trying to solve ProjectEuler.net's problem 3 : "The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ?"

I did my method and it works with 13195. But now i have to do it with 600851475143 (on x64 system), but my algo seems not to be optimezed and i would like to add an percentage progress bar to know if my EXE crash or not. My a var is this percentage...

I DON'T WANT THE ANSWER of Euleur problem 3, i just need to fix my percentage issue...


Solution

  • Marking the numeric value with an M after it will make it a decimal value. And use the correct overload for Round.

    var a = Math.Round(i / 600851475143M * 100, 5);