# Single vs Double - precision floating point numberRSS

## 2 replies

Last post Mar 06, 2006 10:43 AM by Caddre

• dotnetnew123

None

0 Points

36 Posts

### Single vs Double - precision floating point number

Hello,

I have a value, EdgeChangeThreshold which is the minimum change in an edge (yesterday vs today) for a stock details to be displayed on the page

This value will be entered by the users. The calculated formula for the difference in edge is a basis point (abs(previous edge )- abs(current edge))/previous edge (display format 0.0000%) that will be displayed .

In order to validate the value entered based on which I can return the security details, should I use decimal or single or double(System.Struct)? What is the difference?

dotnetnew123

• DarrellNorto...

All-Star

43204 Points

10243 Posts

MVP

### Fixed-point Type

The System.Decimal type is a kind of hybrid between an integer and a floating-point number. It is a 128-bit (16-byte) data structure that can exactly represent values ranging from -79,228,162,514,264,337,593,543,950,335 to negative 79,228,162,514,264,337,593,543,950,335, with up to 29 significant digits. The C# name for this type is decimal. In Visual Basic it's Decimal.

The Decimal type is a structure that consists of a 1-bit sign, a 96-bit integer, and a scaling factor that specifies where to put the decimal point. The scaling factor is a number from 0 to 28, representing the number 10 raised to that power, which is used to divide the 96-bit integer. So, if the integer number is 12 and the scaling factor is 1, then the value represented is 12 divided by 101, or 1.2.

The beauty of this type is that it can exactly represent decimal values—something that's especially important when working with currency values. Whereas floating-point numbers are approximations (albeit very close approximations), decimal values are exact. For example, if you use a floating-point type to add and subtract currency values, eventually you'll end up with a number that has more than just two decimal places. You might end up with 349.999997, for example.

If you use a Decimal type to add currency values, you'll always end up with two decimal places.

Darrell Norton, MVP
Darrell Norton's Blog

Contributor

4150 Points

5249 Posts