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

x
?
Solved

decimal

Posted on 2008-06-26
3
Medium Priority
?
304 Views
Last Modified: 2010-04-15
I would like to decide how many numbers will be behind the decimal point.
For example I have got:  int n1=1,    int n2=3              n1/n3;
What do I do to get only 2 numbers behind the decimal point  :  0,33   or exactly 3 numbers : 0,333  etc.  ?
0
Comment
Question by:johnkainn
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
Rob Siklos earned 200 total points
ID: 21877302
If you want it rounded to 3 decimal places, use: Math.Round(n1/n3, 3);

If you want it *truncated* to n decimal places, multiply by 10^n, call Math.Truncate, then divide by 10^n
0
 

Author Comment

by:johnkainn
ID: 21878335
What datatype should the resultnumber be to show i.e. 0,33?
0
 
LVL 9

Expert Comment

by:Rob Siklos
ID: 21878998
System.Double
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
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…
Suggested Courses

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