Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

rounding down the result of a calculation to the 5th decimal
 Post subject: rounding down the result of a calculation to the 5th decimal Post rating: 0   New post Posted: Thu 11 Aug, 2011, 14:03 
User avatar

User rating: 1
Joined: Wed 06 Jul, 2011, 23:12
Posts: 42
Location: Romania, Bucharest
Dear Sirs,

Developing a strategy, I am calculating the stop loss level for the engine.submitOrder() method.

My problem is that I don't know the code for rounding down the result of my calculation to the 5th decimal, so that the platform will accept my stop loss level.

As you know, the platform only accepts placing order with price levels with a 0.1 pip precision. So need the result of my calculation to look something like: 1,42123

Thank you in advance!


 
 Post subject: Re: rounding down the result of a calculation to the 5th dec Post rating: 0   New post Posted: Thu 11 Aug, 2011, 14:37 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Consider the following function:
private double roundDown(double amount, int decimalPlaces) {
   return (new BigDecimal(amount)).setScale(decimalPlaces, BigDecimal.ROUND_DOWN).doubleValue();
}
If you wish to round to 0.1 pip, you can call it the following way:
double roundedAmount = roundHalfDown(0.1234567, Instrument.EURUSD.getPipScale() + 1)


 
 Post subject: Re: rounding down the result of a calculation to the 5th dec Post rating: 0   New post Posted: Thu 11 Aug, 2011, 15:00 
User avatar

User rating: 1
Joined: Wed 06 Jul, 2011, 23:12
Posts: 42
Location: Romania, Bucharest
Great!

Thank you for the promt answer!


 

Jump to:  

cron
  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com