Posted on 2008-06-26
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.  ?
Question by:johnkainn
  • 2

Accepted Solution

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

Author Comment

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

Expert Comment

by:Rob Siklos
ID: 21878998

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Loop not working 29 47
Iterate a dictionnary to change values 4 53
Parse the OuterHTML Data in the txtfile using c# 4 48
C# Comparing String Arrays. 5 0
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…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

22 Experts available now in Live!

Get 1:1 Help Now