Round off decimal value in Nearest 10 or Zero [duplicate]












0
















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.










share|improve this 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 through Math.Round(yourNumber, 1). Thanks

    – Jignesh Rajput
    Dec 31 '18 at 4:35
















0
















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.










share|improve this 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 through Math.Round(yourNumber, 1). Thanks

    – Jignesh Rajput
    Dec 31 '18 at 4:35














0












0








0









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.










share|improve this question

















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 through Math.Round(yourNumber, 1). Thanks

    – Jignesh Rajput
    Dec 31 '18 at 4:35



















  • 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

















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












2 Answers
2






active

oldest

votes


















1














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 overloadMath.round that takes the decimals parameter of
your choice and convenience.




**






share|improve this answer
























  • I updated my question. I already tried your suggestion.

    – Jignesh Rajput
    Dec 31 '18 at 4:19



















0














Use Math.round and if needed convert the same to string.



  Math.Round(var_name,2)





share|improve this answer






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    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 overloadMath.round that takes the decimals parameter of
    your choice and convenience.




    **






    share|improve this answer
























    • I updated my question. I already tried your suggestion.

      – Jignesh Rajput
      Dec 31 '18 at 4:19
















    1














    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 overloadMath.round that takes the decimals parameter of
    your choice and convenience.




    **






    share|improve this answer
























    • I updated my question. I already tried your suggestion.

      – Jignesh Rajput
      Dec 31 '18 at 4:19














    1












    1








    1







    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 overloadMath.round that takes the decimals parameter of
    your choice and convenience.




    **






    share|improve this answer













    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 overloadMath.round that takes the decimals parameter of
    your choice and convenience.




    **







    share|improve this answer












    share|improve this answer



    share|improve this answer










    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



















    • 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













    0














    Use Math.round and if needed convert the same to string.



      Math.Round(var_name,2)





    share|improve this answer




























      0














      Use Math.round and if needed convert the same to string.



        Math.Round(var_name,2)





      share|improve this answer


























        0












        0








        0







        Use Math.round and if needed convert the same to string.



          Math.Round(var_name,2)





        share|improve this answer













        Use Math.round and if needed convert the same to string.



          Math.Round(var_name,2)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 31 '18 at 4:16









        GauravGaurav

        57029




        57029















            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas