Is there a way to identify the number of decimal places in a floating point number from an array of data?

34 views Asked by At

I am writing a simple script that takes multiple inputs as a set of data. The output should be rounded to one more decimal place than the largest one inputted. For example, if my input data is [3, 6.2, 7, 9, 5.47, 9], the output should be rounded to 3 decimal places because 5.47 has 2 decimal places. I just don't know how to "search" the dataset for the float with the largest amount of decimals and then count them.

This example takes the standard deviation of the dataset and rounds to a certain value "K":

from statistics import stdev
dataset = [float(dataset) for dataset in input().split(",")]
K =  3
print(round(stdev(dataset), K))

I've seen multiple methods (whether it be counting values past a "." or using the as_tuple() method, but I don't know how to apply that to values in an array.

0

There are 0 answers