MIODude,
Since you want a floating point number returned, why do you convert it to an integer in the first place? Since rand will return an integer between 0 and limit-1, simply dividing it with an appropriate divisor (of type float) should render at most the number of decimals that you desire.
Code: Select all
set maxpoint 600
set variable [expr [rand $maxpoint] / 100.0]
I suppose I could illustrate the proper way you would use the int function in this case, though you'll find that it does actually nothing in this case, as the random value is already an integer...
Code: Select all
set maxpoint 6000
set variable [expr {int([rand $maxpoint]) * 0.001}]
This would, however, still return 3 decimals. To sort that, you'd first have to divide the random number by ten, then convert it into an integer, and then divide by one hundred. Also, to properly round up/down, you should really use round() instead of int(), which simply floors the value.
Code: Select all
set maxpoint 6000
set variable [expr {round([rand $maxpoint] / 10) / 100.0}]
Finally, be adviced that in such trivial cases like this, you really don't need the {}, as they're only there to prevent "double evaluation", using them won't change much in these simple cases - just remember that if you do use them, you'll have to keep the whole expression within them.