Solved

What is the difference between Vb.Net decimal and double datatypes?

Posted on 2010-08-16
3
876 Views
Last Modified: 2012-05-10
hi,

Which data type I should use to compare two numeric string values?
I have the below two strings. I need to convert them to decimal/double and find the difference.
Which datatype is more appropriate for this data? Thank you.

dim str1 as string = "5.41245"
dim str2 as string = "4.31245"
0
Comment
Question by:ipjyo
3 Comments
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 250 total points
ID: 33449197
Decimal would be more appropriate

http://visualbasic.about.com/od/usingvbnet/a/decdatatype.htm
http://dotnetkicks.com/csharp/NET_Decimal_vs_float_double_What_s_the_Difference

In short, decimal stores the data exactly up to a certain number of places, whereas doubles store it in binary form as close as a binary can get to the real number.
0
 
LVL 11

Assisted Solution

by:ladarling
ladarling earned 250 total points
ID: 33449257
Single (32 Bit floating point) would be best in this case, actually.
Double is a 64 bit floating point structure, suitible for very large floating point values.
Decimal (128 bit) is not actually a floating point structure:
http://msdn.microsoft.com/en-us/library/ae55hdtk(VS.80).aspx
Quote:

The nonintegral numeric data types are Decimal (128-bit fixed point), Single Data Type (Visual Basic) (32-bit floating point), and Double Data Type (Visual Basic) (64-bit floating point). They are all signed types. If a variable can contain a fraction, declare it as one of these types.

Decimal is not a floating-point data type. Decimal numbers have a binary integer value and an integer scaling factor that specifies what portion of the value is a decimal fraction.
0
 

Author Comment

by:ipjyo
ID: 33449585
Thanks for the clarification.
0

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

23 Experts available now in Live!

Get 1:1 Help Now