Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Formatting a String to a decimal

 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a value that is 6 characters that I want to convert to a 4 position decimal value. For some reason, my little pea brain cannot figure out how to do this! For example, I have the value "000001". I want to be able to convert this string to 00.0001. I've tried a couple of things with DecimalFormat, but still haven't gotten the result I'm looking for. Can anyone give me a push in the right direction?
Thanks!
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You want an integer padded with left zeros of length six as a string and to parse that into a four–place decimal formatted to have two leading zeros. DecimalFormat will try to make sense of the numbers.
This looks like something we can do with a String format method.
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
when your children are suffering from your punishment, tell your them it will help them write good poetry when they are older. Like this tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!