float random.uniform to 4 decimal places in python
Question: I am having problem rounding floating value to a decimal number greater than
1.

    
    
    def float_generator(size=6, chars = 6):
        return random.uniform(size,chars)
    

and i tried

    
    
    target.write(str(float_generator(7,3)))
    

the above returns random float to 1 decimal num like 1.2222 , 1.333333 I want
to generate 7 decimal and 3 points as illustrated in the 7,3

i tried rounding off below. It round up the points instead .

    
    
     target.write(str(format(float_generator(7,3),'.3f')))
    

Please how do i achieve 12345432.123 instead of 1.222343223 ? Any help would
be appreciated.


Answer: here is a solution for you:

    
    
    import random
    def float_generator(size = 6, chars = 6):
        return round(random.uniform(10**(size-1),10**(size)), chars)
    

call it:

    
    
    float_generator(7,3)
    

output example:

    
    
    2296871.988
    

or better:

    
    
    float_generator = lambda size, chars: round(random.uniform(10**(size-1),10**(size)), chars)
    

call it the same way.

