none
Want to Convert String to Decimal having more than 29 digits RRS feed

  • Question

  • Hi All

    I am working on Windows store app - calculator. I want to display result with 32 digits. When I parse 32 digits in decimal, receives exception (Value was either too large or too small for a Decimal.). For e.g. my no. is 22222222222222222222222222222222 and I parse it using decimal.but it gives same exception (Input string was not in a correct format). When I used doubles to do the same then also it gives exception for e.g. if the result is 1.11111111111111E+31 then also it gives exception. If anyone having solution on this please help.

    Thanks in advance,

    Regards,

    Rishi

    Tuesday, February 12, 2013 2:28 PM

Answers

  • Starting from version 4.0, .Net has a class BigInteger, which is an arbitrary precision integer class. If you also want to work with floating point numbers, you will have to look for a third party library for now. Apparently Microsoft is working on a BigFloat class, but it is not out yet.

    Hey, look! This system allows signatures of more than 60 cha

    Tuesday, February 12, 2013 3:11 PM
  • I happen to have thought about writing my own BigFloat class in C++ a few years back. But just using BigInteger makes it a lot easier

    First realise that you can store and process a Value with two Decimal Places in an Int - you just have to multiply it by 100. (It's like saving in Cents instead of Dollars).

    As you want to calculate with values of different you may need to a make a Class as this:

    class MyBigFloat{
      BigInteger number;
      int decimalPostion;
    }

    You of course have to write your own mathemical Functions (or Operators like BigInt does). And your own toString (dividing pi by 1 Millions should be shown as "3,14[numbers omited] E-9"). Nobody want to see a lot of Zeroes.


    Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2

    Tuesday, February 12, 2013 6:56 PM
  • Decimal string can not have a value greater than 9,999,999,999.999...

    Try an alternate

    http://stackoverflow.com/questions/7887774/how-can-i-get-more-than-100-decimal-digits-in-c


    It all Happenz Sendil


    • Edited by sendilg Tuesday, February 12, 2013 3:36 PM
    • Proposed as answer by sendilg Tuesday, February 19, 2013 3:38 AM
    • Marked as answer by Lisa ZhuModerator Tuesday, February 19, 2013 4:11 AM
    Tuesday, February 12, 2013 3:28 PM

All replies

  • Starting from version 4.0, .Net has a class BigInteger, which is an arbitrary precision integer class. If you also want to work with floating point numbers, you will have to look for a third party library for now. Apparently Microsoft is working on a BigFloat class, but it is not out yet.

    Hey, look! This system allows signatures of more than 60 cha

    Tuesday, February 12, 2013 3:11 PM
  • Arno,  I've seen your signature several times before but this time I wanted to take a moment to offer my compliments:   I think it's hilarious.

    Very Well Done, Sir.

    Tuesday, February 12, 2013 3:24 PM
  • Decimal string can not have a value greater than 9,999,999,999.999...

    Try an alternate

    http://stackoverflow.com/questions/7887774/how-can-i-get-more-than-100-decimal-digits-in-c


    It all Happenz Sendil


    • Edited by sendilg Tuesday, February 12, 2013 3:36 PM
    • Proposed as answer by sendilg Tuesday, February 19, 2013 3:38 AM
    • Marked as answer by Lisa ZhuModerator Tuesday, February 19, 2013 4:11 AM
    Tuesday, February 12, 2013 3:28 PM
  • I happen to have thought about writing my own BigFloat class in C++ a few years back. But just using BigInteger makes it a lot easier

    First realise that you can store and process a Value with two Decimal Places in an Int - you just have to multiply it by 100. (It's like saving in Cents instead of Dollars).

    As you want to calculate with values of different you may need to a make a Class as this:

    class MyBigFloat{
      BigInteger number;
      int decimalPostion;
    }

    You of course have to write your own mathemical Functions (or Operators like BigInt does). And your own toString (dividing pi by 1 Millions should be shown as "3,14[numbers omited] E-9"). Nobody want to see a lot of Zeroes.


    Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2

    Tuesday, February 12, 2013 6:56 PM