Solved

decimal

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now