473,387 Members | 1,624 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

problem with divide operation

I have a problem with divide operation,
the example is:
double a =10.0;
double b =220.0;
double divAns = a/b;
the calculation true result is 0.04545454545454545
but for some resone the calculation is changing to get the result
0.0454545468091
if you know how can i get the system to calc the first calculation or if you
know of an object like BigNumber in java that can make
calculation with a specipic precision it could realy help me alot.
Maor

Nov 15 '05 #1
2 12186
Maor,

The reason for this is because of the representation of floating point
numbers. It can not always be exact.

However, you should be able to get a more exact result using the Decimal
structure. It is geared for greater precision when doing floating point
calculations.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Maor Mishkin" <ju**@omnivee.com> wrote in message
news:40********@news.012.net.il...
I have a problem with divide operation,
the example is:
double a =10.0;
double b =220.0;
double divAns = a/b;
the calculation true result is 0.04545454545454545
but for some resone the calculation is changing to get the result
0.0454545468091
if you know how can i get the system to calc the first calculation or if you know of an object like BigNumber in java that can make
calculation with a specipic precision it could realy help me alot.
Maor

Nov 15 '05 #2
You could use decimal type:

decimal val1 = 10.0m;
decimal val2 = 220.0m;
decimal result = val1/val2;
Console.WriteLine(result);
Console.ReadLine();
This will give the expected result

José
"Maor Mishkin" <ju**@omnivee.com> wrote in message
news:40********@news.012.net.il...
I have a problem with divide operation,
the example is:
double a =10.0;
double b =220.0;
double divAns = a/b;
the calculation true result is 0.04545454545454545
but for some resone the calculation is changing to get the result
0.0454545468091
if you know how can i get the system to calc the first calculation or if you know of an object like BigNumber in java that can make
calculation with a specipic precision it could realy help me alot.
Maor

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mike Leahy | last post by:
All... I have a query that calculates various using variables from a survey database. As with any survey, there are many instantces of null values. I'm wondering if there is any way to escape...
17
by: Bob Kensworth | last post by:
Hello. What do these two statements mean? 1) #define stuff(x) (x >> 3) 2)
5
by: Yodai | last post by:
Hi all! I have an int that comes with a value like 0x07fa and I have to turn it into a float value of 204.2 decimal to display it.... if I try to divide it by 10 I get bogus numbers. I presume...
8
by: silentlights | last post by:
Hi, Is there a possibiliy to improve division or Modulo operations in the following, tmp1 = 123; tmp2 = 123; frame = ((char)((tmp1/100)+48)); // Division tmp1 = (tmp2...
52
by: Michel Rouzic | last post by:
I obtain an unwanted behavior from the pow() function : when performing pow(2, 0.5), i obtain 1.414214 when performing pow(2, 1/2), i obtain 1.000000 when performing a=0.5; pow(2, a), i obtain...
7
by: Stephan Rose | last post by:
Ok here is my scenario I have an interface called IScalar which describes a one dimensional number that has a certain unit of measurement. This interface is used to create multiple structures,...
4
by: shuisheng | last post by:
Dear all, Assume I have two big arrays A and B. And I want to element-wise divide A by B. When an element of B is zero, the results are also zero. Such as A = { 2, 4, 0, 6} B = { 1, 0, 0, 2}...
5
by: TimSki | last post by:
Hi, This is very strange... I have a simple query using a recordset thus... set rsID = CreateObject("ADODB.recordset") searchPhrase = "SELECT blah...." rsID.Open searchPhrase, oConn
14
by: Default User | last post by:
Hi, If I have three 64 bit integers and I want to do this operation on them: x*y/z Lets say that what we are multiplying by (y) is offset by what we are dividing by (z) so that the final...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.