Verify number of decimal places

I have a cell where I need to determine the number of decimals (2 digit or 4 digit) in the price that is being placed in that cell in order that I may divide by 100 or 1000 in order to complete the formula and return the proper value. All formula logic is in the google sheets cell…
Thanks is advance!
Jerry

You can use a Math column with the Round formula to control the number of decimals, and then write the rounded value.

Have you considered moving your spreadsheet formulas to the Glide Data Editor?

Thanks for the reply. I am not needing to round them but rather determine whether they are 2 digit or 4 digit and then the calculation changes depending on that result. I have not found how to do the same level of calculations using the Data Editor…would be glad to do that…

Can you share more about the calculations that are done in the spreadsheet?
Maybe I can help you with that.

Maybe you could assume they all have 4? (1.23 = 1.2300)

Or as Darren suggested, see if you can adapt your approach slightly, because it would be surprising that your math operations depend on 2 trailing zeros.

I have a forex trading business and this app is one that will calculate the future take profit and stop loss values. If we use a default ‘stop’ and ‘profit’ targets based on a cell with say 30 pips. A 2 digit currency will need that 30 to be .30 and a 4 digit currency will need it to be .0030 so that is why I need to know the digits before I input the entry price which is what the .30 or .0030 is added/subtracted from. Hope this helps explain. Example: Entry price input at 1.5955 for a buy would need the .0030 to be subtracted so the Stop price would be calculated to be 1.5925 or a sell would be 1.5955 added to the .0030 and stop price would be 1.5985.

1 Like

Don’t you know ahead of time when you create a new currency in your app if it will have 2 or 4 digits?

If you don’t know, what would happen if the entry point for a 4-digit currency were 1.5900? Would you expect your app to identify that it was indeed a 4-digit currency?

This portion is to create an alert for a trade setup. So we are setting those up for any of 21 different currencies and we never know until we are inputting the alerts. I can manually do the math for each off the prices but would rather simply enter the “ENTRY PRICE” for a currency and have the math done in the other 2 automatically.

Try the following in a JavaScript column:

return (p1.toString().split('.')[1] || []).length;

CleanShot 2023-06-19 at 08.37.16@2x

Note: in the example above I configured the Number column as a Text type. I only did that to preserve the formatting - it works the same if it’s configured as a Number type.

2 Likes

Thank you so much!!!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.