问题
I have a sheet in Excel which contains a lot of numbers to varying decimal places. I'm trying to create a table in MySQL to store this data as efficiently as possible, but I need to know the highest number of decimal places in each column. Is there a function which I can use to work this out?
My dataset looks something like this:
Item | Val 1 | Val 2 | Val 3
=====|=======|=======|=======
1 | x.xxx | x.xx | xx.xx
... | x.xx | x.x | xx.xxx
n | xx.x | x.xx | xx.xx
For example, in the Val 1 column, the highest number of decimal places is 3. Given the sheer size of the full dataset, however, it would be difficult for me to manually go through every column and count the highest number of decimal places.
回答1:
May be it can help you. It is an excel formula.
=MAX(LEN(MID(B2:B5,SEARCH(".",B2:B5)+1,LEN(B2:B5)-SEARCH(".",B2:B5))))
Press Ctrl+Shift+Enter as it is an array formula.
回答2:
If you are using VBA, VB.NET or similar you can use string functions to count the chars after '.' or ','
回答3:
I am not sure about the actual excel functions to use, but my way of doing it would be to replace everything up to and including the separator with nothing and then taking the strlen of the rest.
I would do that in 'counter-sheet' and make a formula that did this for every cell in the linked 'dataset-sheet'.
At the end of each column in the counter-sheet i would show the max value and at the end of that row I would show the max value across the columns.
If I were to do it in excel, that is. It would be easier with a scripting language like python if the dataset looks exactly like You describe it.
First, however, find out if you need to be that efficient in mysql - premature optimization can drain good manpower.
来源:https://stackoverflow.com/questions/33849428/is-there-a-way-to-find-the-largest-number-of-decimal-places-in-an-excel