Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. which datatype will be appropriate for Ratio calculation in C#

which datatype will be appropriate for Ratio calculation in C#

Scheduled Pinned Locked Moved C#
csharp
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kumar bs
    wrote on last edited by
    #1

    Hi, Can anybody tell which datatype of c# viz Float, double , decimal will be appropriate for calculating percentage (100%) kumar

    L A 2 Replies Last reply
    0
    • K kumar bs

      Hi, Can anybody tell which datatype of c# viz Float, double , decimal will be appropriate for calculating percentage (100%) kumar

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      float is enough. It should be precise enough for most cases.

      1 Reply Last reply
      0
      • K kumar bs

        Hi, Can anybody tell which datatype of c# viz Float, double , decimal will be appropriate for calculating percentage (100%) kumar

        A Offline
        A Offline
        albCode
        wrote on last edited by
        #3

        The float data type float data type is the first of 3 data types that can store floating point numbers and actually this is the smallest of the 3 types. float variables store floating point numbers from 1.5 times 10 to the 45 th (±1.5 × 10-45 ) to 3.4 times 10 to the 38 th (±3.4 × 1038 ) in 32 bit. And this type has a precision to 7 numbers. The double data type double data type variables can store floating point numbers from 5 times 10 to the 324 th (±5.0 × 10-324 ) to 1.7 times 10 the 308 th (±1.7 × 10308 ) in 64-bit. And this type has a precision to 15-16 numbers. The decimal data type decimal data type variables can store 1 times 10 to the 28th 1.0 × 10-28 and 7.9 times 10 to the 28 th 7.9 × 1028 in 128 bit. If you think about this type you will note that it has a greater precision and a smaller range and that’s we exactly needs for financial calculations also note that decimal data type has a Precision of 28-29 significant digits.

        M 1 Reply Last reply
        0
        • A albCode

          The float data type float data type is the first of 3 data types that can store floating point numbers and actually this is the smallest of the 3 types. float variables store floating point numbers from 1.5 times 10 to the 45 th (±1.5 × 10-45 ) to 3.4 times 10 to the 38 th (±3.4 × 1038 ) in 32 bit. And this type has a precision to 7 numbers. The double data type double data type variables can store floating point numbers from 5 times 10 to the 324 th (±5.0 × 10-324 ) to 1.7 times 10 the 308 th (±1.7 × 10308 ) in 64-bit. And this type has a precision to 15-16 numbers. The decimal data type decimal data type variables can store 1 times 10 to the 28th 1.0 × 10-28 and 7.9 times 10 to the 28 th 7.9 × 1028 in 128 bit. If you think about this type you will note that it has a greater precision and a smaller range and that’s we exactly needs for financial calculations also note that decimal data type has a Precision of 28-29 significant digits.

          M Offline
          M Offline
          MCSD Gandalf
          wrote on last edited by
          #4

          One more quick thing on Decimal datatypes. Although the C# language considers this a primitive datatype, the CLR does NOT. From a practical standpoint, this means that manipulating Decimal datatypes is slower than working with the other datatypes. Also, the checked and unchecked operators, and compiler switches have no effect on Decimal datatypes, which ALSO means that Decimal datatypes ALWAYS throw an OverflowException if the operation can't be done safely. I was surprised by this, I am pretty sure I read it in Jeff Richter's book, and played with it some and he's right. I HATE it when that happens!:laugh:

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups