Solved

decimal

Posted on 2008-06-26
3
297 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
[X]
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
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET - Refactor Class per SOLID principles 2 43
Fastest way to get file count in MS Server 2012 3 36
How does this modal work? 3 33
msiexec won't run 4 29
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Suggested Courses

738 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