## 9 replies

Last post Jun 05, 2013 04:57 PM by dblaire

Member

107 Points

297 Posts

### Math.Round Error

I am using the following to round a number without any decimails showing. Midpoint to the the next number i.e 1.5 =>2

```@Math.Round(finalscore)
```

I am getting the following error:

The call is ambiguous between the following methods or properties: 'System.Math.Round(double)' and 'System.Math.Round(decimal)'

• oned_gk

All-Star

52523 Points

15672 Posts

### Re: Math.Round Error

use double type finalscore. finalscore= Math .Round(finalscore)
Programming to simplify, don't look for difficult way
• Prashant Kum...

Star

8561 Points

2044 Posts

### Re: Math.Round Error

May 31, 2013 08:11 PM|Prashant Kumar|LINK

What is the data type of finalscore? How are you calculating it?

Make sure that finalscore is of type decimal (or double).

PKS
• bzdarko

Member

5 Points

22 Posts

### Re: Math.Round Error

just cast finalscore as a double.

@Math.Round((double)finalscore)

-Bill
• dblaire

Member

690 Points

185 Posts

### Re: Math.Round Error

```@{
decimal amount = 0.685M;

decimal rounded3 = decimal.Round(amount, 2, MidpointRounding.AwayFromZero);

@rounded3 <br />
}

// Displayed as:
//                    0.69```

Member

107 Points

297 Posts

### Re: Math.Round Error

What I am looking for is:

73 / 3 = 24.333 rounded to 24 and let say if the resut is 24.512 then rounded to 25

I don't need to display any decimals.

• GmGregori

Contributor

4946 Points

873 Posts

### Re: Math.Round Error

• Rion William...

All-Star

114593 Points

18503 Posts

MVP

### Re: Math.Round Error

Jun 04, 2013 04:00 PM|Rion Williams|LINK

The Math.Round() method actually accepts additional parameters that handle things like Midpoint Rounding rules that you may want to look into, however it should be working properly if you specify the value provided as a decimal or a double :

```@{Decimal finalscore = 1.5m;}

<!-- This will yield 2 -->
@Math.Round(finalscore)```

you could handle this by simply casting your finalscore variable as well :

```@{var finalscore = 1.5;}

<!-- This will yield 2 -->
@Math.Round((double)finalscore)```

Since you are actually evaluating an expression within your Round method, you'll need to explicitly set the type of the value being processed within it :

`@Math.Round((double)73 / 3)`

or you could also handle this by simply using the shorthand identifer for a datatype such as m, f, or d :

`@Math.Round(73d / 3)`

Member

107 Points

297 Posts

### Re: Math.Round Error

Just an added update that your variable must initially be declared  double:

double mynymber = 0;

@Math.Round((double)mynymber / 3);

• dblaire

Member

690 Points

185 Posts

### Re: Math.Round Error

```@{