Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Prevent Rounding of numbers

Posted on 2013-11-22
2
241 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 44

Accepted Solution

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

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

839 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