Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

Prevent Rounding of numbers

I have the following code that shows me a value of 4.0, but I know that is wrong. When I calculate 1791 / 365 I get 4.906849315068493. My value shows up at 4.0. At the least I would like it to calculate out to 5.0. Still it would be nice to see 4.90. What am I doing wrong?

                Int32 bb = (Int32)DataBinder.Eval(e.Row.DataItem, "DAYS"); // This value calculates to 1791
                double cc = bb / 365;
                lbl.Text = cc.ToString();

Open in new window

0
NickMalloy
Asked:
NickMalloy
  • 2
1 Solution
 
AndyAinscowFreelance programmer / ConsultantCommented:
Does this help.  (You were dividing two integers before)
double cc = bb / 365.0;
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
ps.  You might also want ToString("0.00"); if you wanted it formatting to 2 decimal places.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now