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 :

Member

107 Points

297 Posts

## Math.Round Error

May 31, 2013 07:41 PM|engcanada|LINK

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

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)'

All-Star

52523 Points

15672 Posts

## Re: Math.Round Error

May 31, 2013 07:55 PM|oned_gk|LINK

Suwandi - Non Graduate Programmer

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).

Member

5 Points

22 Posts

## Re: Math.Round Error

Jun 01, 2013 02:46 AM|bzdarko|LINK

just cast finalscore as a double.

@Math.Round((double)finalscore)

Member

690 Points

185 Posts

## Re: Math.Round Error

Jun 04, 2013 03:00 PM|dblaire|LINK

Member

107 Points

297 Posts

## Re: Math.Round Error

Jun 04, 2013 03:10 PM|engcanada|LINK

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.

Contributor

4946 Points

873 Posts

## Re: Math.Round Error

Jun 04, 2013 03:53 PM|GmGregori|LINK

Use

Pay attention to "3d" instead of "3" as stated in C# The call is ambiguous between the following methods or properties: 'System.Math.Round(double, int)' and 'System.Math.Round(decimal, int)

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 :

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

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 :

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

Member

107 Points

297 Posts

## Re: Math.Round Error

Jun 05, 2013 02:16 PM|engcanada|LINK

Just an added update that your variable must initially be declared

double:double mynymber = 0;

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

Member

690 Points

185 Posts

## Re: Math.Round Error

Jun 05, 2013 04:57 PM|dblaire|LINK