Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Convert String to BigDecimal

 
Abhishek Mish
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to convert a String with value as 00000101001 to BigDecimal.
Just using the below code:
String str="00000101001 ";
BigDecimal bd= new BigDecimal (str);
after conversion to BigDecimal i am getting the value as 101001.
How can i get the exact String 00000101001 converted to BigDecimal.

Thanks,
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actual numbers -- whether they are BigDecmials, ints, longs, floats, bytes, or what-have-you -- never include leading zeros. They have no particular format at all: they represent an abstract mathematical concept. If you want to display leading zeros, you have to provide them yourself.

(Note that in Java, if you write an integer literal with a leading 0, it's assumed to be a number in octal (base 8!))
 
Gareth Lloyd
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you trying to convert binary to decimal?
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gareth Lloyd wrote:Are you trying to convert binary to decimal?
In which case a look at the BigInteger constructors might be helpful. Note that is BigInteger, not BigDecimal, but the String you quoted is an integer.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic