Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Prevent Rounding of numbers

Posted on 2013-11-22
2
Medium Priority
?
246 Views
Last Modified: 2013-11-22
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
Comment
Question by:NickMalloy
  • 2
2 Comments
 
LVL 45

Accepted Solution

by:
AndyAinscow earned 1400 total points
ID: 39669048
Does this help.  (You were dividing two integers before)
double cc = bb / 365.0;
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 39669056
ps.  You might also want ToString("0.00"); if you wanted it formatting to 2 decimal places.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Integration Management Part 2
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question