Round off decimal value in Nearest 10 or Zero [duplicate]
This question already has an answer here:
C# - Math.Round
5 answers
Following values i would like to convert to round off figure. likes:
60.72 --> 60.70
170.76 --> 170.80
Currently, I'm converted to round off value using below method:
getFee.ServiceRequestFee.ToString("N")
I'm not sure which Match.Round
method suitable to my requirement.
Edit:
protected string Getroundoffdecimalvalue(string servicerequestsfee_val)
{
servicerequestsfee_val = Math.Round(Convert.ToDecimal(servicerequestsfee_val), 2).ToString();
return servicerequestsfee_val;
}
I used this function even after i return 60.72 only and my expectation should 60.70.
c# double rounding
marked as duplicate by Community♦ Dec 31 '18 at 4:39
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
C# - Math.Round
5 answers
Following values i would like to convert to round off figure. likes:
60.72 --> 60.70
170.76 --> 170.80
Currently, I'm converted to round off value using below method:
getFee.ServiceRequestFee.ToString("N")
I'm not sure which Match.Round
method suitable to my requirement.
Edit:
protected string Getroundoffdecimalvalue(string servicerequestsfee_val)
{
servicerequestsfee_val = Math.Round(Convert.ToDecimal(servicerequestsfee_val), 2).ToString();
return servicerequestsfee_val;
}
I used this function even after i return 60.72 only and my expectation should 60.70.
c# double rounding
marked as duplicate by Community♦ Dec 31 '18 at 4:39
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
So, Bankers’ Rounding?
– Jimi
Dec 31 '18 at 4:11
why not overload math.round to make it suitable for your requirement?
– Common Man
Dec 31 '18 at 4:15
1
See the examples in the link I posted. If you need a string representation, you can use"N2"
as format.
– Jimi
Dec 31 '18 at 4:25
@CommonMan - you might be correct. I found the solution throughMath.Round(yourNumber, 1)
. Thanks
– Jignesh Rajput
Dec 31 '18 at 4:35
add a comment |
This question already has an answer here:
C# - Math.Round
5 answers
Following values i would like to convert to round off figure. likes:
60.72 --> 60.70
170.76 --> 170.80
Currently, I'm converted to round off value using below method:
getFee.ServiceRequestFee.ToString("N")
I'm not sure which Match.Round
method suitable to my requirement.
Edit:
protected string Getroundoffdecimalvalue(string servicerequestsfee_val)
{
servicerequestsfee_val = Math.Round(Convert.ToDecimal(servicerequestsfee_val), 2).ToString();
return servicerequestsfee_val;
}
I used this function even after i return 60.72 only and my expectation should 60.70.
c# double rounding
This question already has an answer here:
C# - Math.Round
5 answers
Following values i would like to convert to round off figure. likes:
60.72 --> 60.70
170.76 --> 170.80
Currently, I'm converted to round off value using below method:
getFee.ServiceRequestFee.ToString("N")
I'm not sure which Match.Round
method suitable to my requirement.
Edit:
protected string Getroundoffdecimalvalue(string servicerequestsfee_val)
{
servicerequestsfee_val = Math.Round(Convert.ToDecimal(servicerequestsfee_val), 2).ToString();
return servicerequestsfee_val;
}
I used this function even after i return 60.72 only and my expectation should 60.70.
This question already has an answer here:
C# - Math.Round
5 answers
c# double rounding
c# double rounding
edited Dec 31 '18 at 4:18
Jignesh Rajput
asked Dec 31 '18 at 4:07
Jignesh RajputJignesh Rajput
3,2852244
3,2852244
marked as duplicate by Community♦ Dec 31 '18 at 4:39
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Community♦ Dec 31 '18 at 4:39
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
So, Bankers’ Rounding?
– Jimi
Dec 31 '18 at 4:11
why not overload math.round to make it suitable for your requirement?
– Common Man
Dec 31 '18 at 4:15
1
See the examples in the link I posted. If you need a string representation, you can use"N2"
as format.
– Jimi
Dec 31 '18 at 4:25
@CommonMan - you might be correct. I found the solution throughMath.Round(yourNumber, 1)
. Thanks
– Jignesh Rajput
Dec 31 '18 at 4:35
add a comment |
So, Bankers’ Rounding?
– Jimi
Dec 31 '18 at 4:11
why not overload math.round to make it suitable for your requirement?
– Common Man
Dec 31 '18 at 4:15
1
See the examples in the link I posted. If you need a string representation, you can use"N2"
as format.
– Jimi
Dec 31 '18 at 4:25
@CommonMan - you might be correct. I found the solution throughMath.Round(yourNumber, 1)
. Thanks
– Jignesh Rajput
Dec 31 '18 at 4:35
So, Bankers’ Rounding?
– Jimi
Dec 31 '18 at 4:11
So, Bankers’ Rounding?
– Jimi
Dec 31 '18 at 4:11
why not overload math.round to make it suitable for your requirement?
– Common Man
Dec 31 '18 at 4:15
why not overload math.round to make it suitable for your requirement?
– Common Man
Dec 31 '18 at 4:15
1
1
See the examples in the link I posted. If you need a string representation, you can use
"N2"
as format.– Jimi
Dec 31 '18 at 4:25
See the examples in the link I posted. If you need a string representation, you can use
"N2"
as format.– Jimi
Dec 31 '18 at 4:25
@CommonMan - you might be correct. I found the solution through
Math.Round(yourNumber, 1)
. Thanks– Jignesh Rajput
Dec 31 '18 at 4:35
@CommonMan - you might be correct. I found the solution through
Math.Round(yourNumber, 1)
. Thanks– Jignesh Rajput
Dec 31 '18 at 4:35
add a comment |
2 Answers
2
active
oldest
votes
Math.Round(yourNumber, 1)
The second parameter is number of decimal places to round to. In your case you want 1 decimal place as an end result.
**
You need to overload
Math.round
that takes the decimals parameter of
your choice and convenience.
**
I updated my question. I already tried your suggestion.
– Jignesh Rajput
Dec 31 '18 at 4:19
add a comment |
Use Math.round and if needed convert the same to string.
Math.Round(var_name,2)
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Math.Round(yourNumber, 1)
The second parameter is number of decimal places to round to. In your case you want 1 decimal place as an end result.
**
You need to overload
Math.round
that takes the decimals parameter of
your choice and convenience.
**
I updated my question. I already tried your suggestion.
– Jignesh Rajput
Dec 31 '18 at 4:19
add a comment |
Math.Round(yourNumber, 1)
The second parameter is number of decimal places to round to. In your case you want 1 decimal place as an end result.
**
You need to overload
Math.round
that takes the decimals parameter of
your choice and convenience.
**
I updated my question. I already tried your suggestion.
– Jignesh Rajput
Dec 31 '18 at 4:19
add a comment |
Math.Round(yourNumber, 1)
The second parameter is number of decimal places to round to. In your case you want 1 decimal place as an end result.
**
You need to overload
Math.round
that takes the decimals parameter of
your choice and convenience.
**
Math.Round(yourNumber, 1)
The second parameter is number of decimal places to round to. In your case you want 1 decimal place as an end result.
**
You need to overload
Math.round
that takes the decimals parameter of
your choice and convenience.
**
answered Dec 31 '18 at 4:14
Common ManCommon Man
1,27221226
1,27221226
I updated my question. I already tried your suggestion.
– Jignesh Rajput
Dec 31 '18 at 4:19
add a comment |
I updated my question. I already tried your suggestion.
– Jignesh Rajput
Dec 31 '18 at 4:19
I updated my question. I already tried your suggestion.
– Jignesh Rajput
Dec 31 '18 at 4:19
I updated my question. I already tried your suggestion.
– Jignesh Rajput
Dec 31 '18 at 4:19
add a comment |
Use Math.round and if needed convert the same to string.
Math.Round(var_name,2)
add a comment |
Use Math.round and if needed convert the same to string.
Math.Round(var_name,2)
add a comment |
Use Math.round and if needed convert the same to string.
Math.Round(var_name,2)
Use Math.round and if needed convert the same to string.
Math.Round(var_name,2)
answered Dec 31 '18 at 4:16
GauravGaurav
57029
57029
add a comment |
add a comment |
So, Bankers’ Rounding?
– Jimi
Dec 31 '18 at 4:11
why not overload math.round to make it suitable for your requirement?
– Common Man
Dec 31 '18 at 4:15
1
See the examples in the link I posted. If you need a string representation, you can use
"N2"
as format.– Jimi
Dec 31 '18 at 4:25
@CommonMan - you might be correct. I found the solution through
Math.Round(yourNumber, 1)
. Thanks– Jignesh Rajput
Dec 31 '18 at 4:35