473,387 Members | 1,520 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.

Fuzzy math!

Hi,

I am having a slight problem with some code. I perform some additions
and subtractions on some 2 digit decimals, multiply by -1.0 and wind up
with a number with 12 digits of precision.

? (83538.18 + 0.0 + 0.0 - 40000.0 - 0.0) * -1.0
-43538.179999999993
I have replaced all the variables with their values for this example.
Does anyone know of a problem with VB's handling of decimals? And, if
so, what can I do about it (other than just rounding it off)?

Thanks,
Tony

Nov 21 '05 #1
3 985

sc******@computer.org wrote:
Hi,

I am having a slight problem with some code. I perform some additions
and subtractions on some 2 digit decimals
No, you perform some additions and subtractions on some *floating-point
numbers*. Floating point arithmetic is not exact.

, multiply by -1.0 and wind up with a number with 12 digits of precision.

? (83538.18 + 0.0 + 0.0 - 40000.0 - 0.0) * -1.0
-43538.179999999993
? (83538.18D + 0.0D + 0.0D - 40000.0D - 0.0D) * -1.0D
-43538.18D

(I use the deprecated type declaraction character 'D' here; CDec(...)
has the same effect)


I have replaced all the variables with their values for this example.
Does anyone know of a problem with VB's handling of decimals?
Here's one you might like:

? 0.1 + 0.1 + 0.1 - 0.3
And, if
so, what can I do about it (other than just rounding it off)?


Use fixed-point types to hold exact values.

--
Larry Lard
Replies to group please

Nov 21 '05 #2
Thanks,

I switched from doubles to decimals and that seems to work.

Nov 21 '05 #3
<sc******@computer.org> schrieb:
I am having a slight problem with some code. I perform some additions
and subtractions on some 2 digit decimals, multiply by -1.0 and wind up
with a number with 12 digits of precision.

? (83538.18 + 0.0 + 0.0 - 40000.0 - 0.0) * -1.0
-43538.179999999993
I have replaced all the variables with their values for this example.
Does anyone know of a problem with VB's handling of decimals? And, if
so, what can I do about it (other than just rounding it off)?


In addition to the other replies:

That's a characteristic of floating point numbers.

<URL:http://research.microsoft.com/~hollasch/cgindex/coding/ieeefloat.html>
<URL:http://www.math.grin.edu/~stone/courses/fundamentals/IEEE-reals.html>
<URL:http://support.microsoft.com/?scid=kb;[LN];42980>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #4

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

Similar topics

4
by: Tim Mackey | last post by:
hi, when a user reaches a 404 page not found on my web site, i want to give them one or more 'best guess' links to the page they are looking for (MS do this on their site...). i have a list of...
1
by: Ray Gardener | last post by:
I was wondering if anyone had tried implementing fuzzy logic set concepts in C++, because in FL, the concept of "type" or "class" is fuzzy; things belong (or are of) a given type only by degree....
1
by: Evaluating Fuzzy SW | last post by:
Hi All We are using soundex (and later tried Nysiis) for fuzzy name search software. But we faced a lot of problems the search accuracy was not very good also we saw a lot of misses of...
0
by: DNKMCA | last post by:
Hi, i was building a internet based search engine and heard of fuzzy search algorithms. Can anybody give fuzzy logic search algorithm for string search -dnk
3
by: michael.f.morrison | last post by:
Hi all, Does anyone now if there is a way to do a fuzzy string compare in c#? For example, comparing 'cat' to 'cats' would return something like a 90% match ratio. I was told that this type of ...
1
by: Alberto | last post by:
Does anybody knows if .net has a library of classes to work with fuzzy logic? Thank you
24
by: cassetti | last post by:
Here's the issue: I have roughly 20 MS excel spreadsheets, each row contains a record. These records were hand entered by people in call centers. The problem is, there can and are duplicate...
11
by: John Henry | last post by:
I am just wondering what's with get_close_matches() in difflib. What's the magic? How fuzzy do I need to get in order to get a match?
14
by: Steve Bergman | last post by:
I'm looking for a module to do fuzzy comparison of strings. I have 2 item master files which are supposed to be identical, but they have thousands of records where the item numbers don't match in...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.