Getting first digit of Account's balance

Back to topics list To post a new topic, please log in or register
avatar
2
hals69 2015.04.02 22:48
 

Hello,

I'm trying to do some mathematical equations within my EA , but the problem is one of equations  requires the first number of account's balance . For example if the balance is 506.60 I want to get this value "5" , if it is 432.32 I want to get "4" . So how can it be done ? 

Note : To get the current balance I use AccountBalance();

 

avatar
108
eddie 2015.04.02 23:08 #
 

Hi hals69!

Try

  long value = StringToInteger (StringSubstr (DoubleToString (AccountBalance ( )), 0, 1));


avatar
12985
WHRoeder 2015.04.03 02:56 #
 
int d = int( AccountBalance() / 100); // 4xx.xx/100=4.xxx 5xx.xx/100=5
What if the balance is 99, do you want zero? What if the balance is 1000, do you want 10? If not then eddie's idea works. If yes, then mine.
Back to topics list  

To add comments, please log in or register