Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

Using C#.

Need small help. Though it is showing as small i am unable to figure it out.

I am having a calculation which returns result into float as
43.518265


I would like to format it as 43.52 not 44.0 or 44.6 or 44.60

I have tried

Math.Round(MedicaidFee, 1, MidpointRounding.AwayFromZero)


Math.Round(MedicaidFee)

Math.Round((Math.Round(CareSourceFee * 20, MidpointRounding.AwayFromZero) / 20) 2)


Nothing wokring out.

Can anyone help me for the same.

Thanks In advance.

What I have tried:

Math.Round(MedicaidFee, 1, MidpointRounding.AwayFromZero)


Math.Round(MedicaidFee)


Math.Round((Math.Round(CareSourceFee * 20, MidpointRounding.AwayFromZero) / 20) 2)
Posted
Updated 24-Jun-18 20:42pm

If your intent is to format it for displaying, you can simply do:
MedicaidFee.ToString(".00")


If you want to actually round the value as in your attempts, you could do:
Math.Round(MedicaidFee * 100) / 100;
 
Share this answer
 
Hi, Have you tried this code:
<pre lang="c#">
float a = 43.518265F;
float b = (float)Math.Round(a, 2);


Best regards
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900