• Post Reply Bookmark Topic Watch Topic
  • New Topic

Double parsing

 
Amit A. Patil
Ranch Hand
Posts: 38
  • 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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 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
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you ..
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15758
74
Android IntelliJ IDE Java Scala Spring
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper's solutions looks very simple! You can go for that.

Thanks Jesper!
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!