File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Double parsing

 
Amit A. Patil
Ranch Hand
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a fixed width string of 8 bytes. The last two bytes indicate the frational part how do i parse it to double

example 00001223 is actaully 12.23
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Take a substring of your string, with the first 6 characters
2. Append a "."
3. Append the last 2 chracters
4. use Double(String) constructor to make a new Double

I'm sure you can make the code yourself
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Amit,


The last two bytes indicate the frational part how do i parse it to double


There is a method named doubleValue() of java.lang.Byte Wrapper class which returns the double representation of the byte primitive value it has.

If you need to have >1 bits, then you may need to a bit manipulation with logical ANDing. And then use the Double(String) constructor for getting the double value in turn.

HtH.
[ June 20, 2007: Message edited by: Raghavan Muthu ]
 
Amit A. Patil
Ranch Hand
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you ..
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even simpler:

1. Parse the string using Double.parseDouble
2. Divide the result by 100.0
[ June 21, 2007: Message edited by: Jesper Young ]
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper's solutions looks very simple! You can go for that.

Thanks Jesper!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic