Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7399583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:04:44+00:00 2026-05-29T04:04:44+00:00

I have writed this piece of code in java: String[] tokens = strLine.split(delims); SimpleOrderRequest

  • 0

I have writed this piece of code in java:

String[] tokens = strLine.split(delims);
SimpleOrderRequest bet = new SimpleOrderRequest();
long Id = Long.parseLong(tokens[1].trim());
byte polarity =  Byte.parseByte(tokens[2].trim());
float price = Float.parseFloat(tokens[3].trim());
float stake = Float.parseFloat(tokens[4].trim());
bet.selectionId = Id;
bet.polarity = polarity;
bet.stake = new BigDecimal(stake) ;
bet.price = new BigDecimal(price) ;

Where tokens[1],tokens[2],tokens[3],tokens[4] are numbers in different formats. The problem is that i have to cut the numbers to the first digit after the comma in order to send the data to wsdl service. Namely, when the the string that i read is:

0.00426,    12955094,  1,    100.,   1.
0.00050,    12954726,  1,    100.,   1. 

all works fine and bet.stake=1. and bet.price=100. But when the string is in the form:

0.00154,    13189533,  1,    2.10,   34.77

then bet.stake=34.770000457763671875 and bet.price=2.099999904632568359375 , and the wsdl service don’t allow me to place the request, so i have to cut the number. Can i do this directly when i am parsing the numbers? if no what i have to do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:04:45+00:00Added an answer on May 29, 2026 at 4:04 am

    You shouldn’t be using float to represent currency values in the first place. Just use:

    BigDecimal price = new BigDecimal(tokens[3].trim());
    

    (etc)

    It looks like you’ve got the right data type within SimpleOrderRequest – so why would you introduce a binary floating point conversion?

    It’s important that you understand how binary floating point works – there are umpteen questions on Stack Overflow about it. Basically, you should normally use float and double for “natural” values such as height and weight, where magnitude is important but there’s really no such thing as a precise value – and use BigDecimal for “artificial” values where you can certainly have exactly $1.10 for example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this piece of code as part of a socks5 proxy server implementation.
I have this piece of code using standard sockets: void set_fds(int sock1, int sock2,
Ok so i have this piece of code: def findNReplaceRegExp(file_name, regexp, replaceString, verbose=True, confirmationNeeded=True):
Am getting errors in this piece of code; I have placed the error messages
In javascript suppose you have this piece of code: <div> <script type=text/javascript>var output =
I have this piece of code which gives to SAXParseError i.e., it is not
Have a look at this piece of code: my @arr = (1, 2); my
I have this piece of code: <script language=javascript type=text/jscript> document.write(<img src='http://dm.leadgenesys.com/jpgp.lgt?en=P.........TP_Q=&amp;ur=' + escape(document.referrer) +
I have this piece of code var f = function() { this.x = 100;
I have this piece of code that adds a BOM UTF-8 to an outputstream

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.