How to get a random number without trailing zers from rand()?

I used rand() to get a list of random numbers between 0 and 1. It gives me something like

[.30000000, .50000000, .20000000]

But I want this to be like [.3,.5,.2]. As my code tells that both the above lists are unequal !!! How ? kindly explain me.

regards,

Athar

Axel Vogt's picture

you could try fnormal or evalf[n]

[.30000000, .50000000, .20000000]: evalf[1](%);
                           [0.3, 0.5, 0.2]

[.30000000, .50000000, .20000000]: convert(%,rational): evalf[1](%); 
                           [0.3, 0.5, 0.2]

[.30000000, .50000000, .20000000]: fnormal(%,3);

                        [0.300, 0.500, 0.200]

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
}