Check Decimal Places

honkin

Active Member
Joined
Mar 20, 2012
Messages
385
Office Version
  1. 2016
Platform
  1. MacOS
hi

I am looking for a way to have Excel check the number of decimal places for a formula.

I currently have the following formula =IF(F10 > F8, (F8-F14)*10000, (F14-F8)*10000) which calculates pips for me based on whether the trade is a buy or a sell, but just realised that not all currency pairs have the same amount of decimal places.

My broker uses 5 decimal places for pairs, but there are a handful that only use 3 decimal places and I need the calculation to reflect that. So if it is a normal 5 decimal pair, the above will work fine, but if it is only a 3 decimal pair, the formula will need to be =IF(F10 > F8, (F8-F14)*100, (F14-F8)*100)

If someone could possibly help me, that would be greatly appreciated.

regards

honkin
 
OK, my apologies Vladimir. AS soon as I saw ROUND in there, it threw me.

The code does not appear to work correctly in at least 1 cell. Here is what I input in F8 - 88.23000 and in F10 - 87.67900. The answer from the following
Code:
=IF(F10>F8,(F10-F8)*10^(LEN(ROUND(MOD((F10-F8),1),5))-3),(F8-F10*10^(LEN(ROUND(MOD((F8-F10),1),5))-3)))
was -8679.67. The answer should be 55.1, which is F8 minus F10 and the decimal moved. The answer must always be a positive number, as you are subtracting the smaller from the larger.

So what there is in my template is an entry price, a stop price and 4 target prices.

For the stop calculation, if F10 is larger than F8, the the position is a Sell; if F8 is larger than F8, the position is a Buy. To calculate my stop it is simply either F8 - F10, or F10 - F8, displayed like 55.1 instead of 0.551

Final Target - now, for some reason, this one calculated correctly. Input was F8 88.23000 and F14 was 89.12300. The answer is 89.3 and worked fine.
Code:
=IF(F10>F8, (F8-F14)*10^(LEN(ROUND(MOD((F8-F14),1),5))-3), (F14-F8)*10^(LEN(ROUND(MOD((F14-F8),1),5))-3))

The 4 targets seem to work as well as the Final target, so for some reason it just does not calculate correctly for Stop

Thanks so much. It does appear to be getting there, but cannot work out why it is not calculating correctly in just that 1 cell

regards

honkin
 
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
The code does not appear to work correctly in at least 1 cell. Here is what I input in F8 - 88.23000 and in F10 - 87.67900. The answer from the following
Rich (BB code):
=IF(F10>F8,(F10-F8)*10^(LEN(ROUND(MOD((F10-F8),1),5))-3),(F8-F10*10^(LEN(ROUND(MOD((F8-F10),1),5))-3)))
was -8679.67. The answer should be 55.1, which is F8 minus F10 and the decimal moved. The answer must always be a positive number, as you are subtracting the smaller from the larger.
There is a typo in your formula (I've marked it in Red), here is the fixed one which returns 55.1:
=IF(F10>F8, (F10-F8)*10^(LEN(ROUND(MOD((F10-F8),1),5))-3), (F8-F10)*10^(LEN(ROUND(MOD((F8-F10),1),5))-3))
 
Last edited:
Upvote 0
Please pay your attention on fact that if F8 = 88.239 and F10 = 87.679 then formula returns 5.6 because F8 - F10 = 0.56 and factor = 10 in this case.
Not sure if it's correct logic for you or not, but it concerns to Gerry's warning as well.
 
Upvote 0
understood Vladimir, but not sure why the other cells calculate correctly based on the same formula.

And just to correct you, the formula did not return 0.56, it returned -8679.67, which is miles from the correct result.

cheers and thanks for trying to assist

regards

honkin
 
Upvote 0
And just to correct you, the formula did not return 0.56, it returned -8679.67, which is miles from the correct result
In your formula of post #11 some parentheses are not on the correct place.
See my post #13 with fixing it.
Below is the cells layout and formula which returns correct result 55.1
Excel Workbook
EF
855.188.23
9
1087.679
Sheet
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top