Solved

decimal

Posted on 2008-06-26
3
295 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 50 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

837 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