Reputation: 365
public void ChangeTexts(long length, int position, int percent, double speed)
{
Label3.Text = "File Size: " + Math.Round((length / 1024), 2) + " KB";
Severity Code Description Project File Line Suppression State Error CS0121 The call is ambiguous between the following methods or properties: 'Math.Round(double, int)' and 'Math.Round(decimal, int)'
Upvotes: 0
Views: 247
Reputation: 12491
Error is self explanary. You should specify what type you want to use. It happends becouse Math.Round()
method doesn't have overload for long
.
So you can do it like this:
public void ChangeTexts(long length, int position, int percent, double speed)
{
Label3.Text = "File Size: " + Math.Round((length / 1024d), 2) + " KB";
}
Now you operate with double
type. d
is a literal for double
type. Now expression (double)length / 1024d
will return double
. And Math.Round
has overload for it.
Upvotes: 2
Reputation: 1500525
You're currently dividing by 1024 in integer arithmetic and then rounding the result. In other words, you're rounding something that's already an integer - not really useful.
The simplest fix is to divide by 1024.0 instead, to make it happen in double
arithmetic:
Label3.Text = "File Size: " + Math.Round((length / 1024.0), 2) + " KB";
Or better, just do it within the formatting itself:
Label3.Text = $"File Size: {length / 1024.0:0.00}KB";
Upvotes: 2