0

I'm trying to create a random float generator. The float must be 2 decimal places and between the values 0.50 and 999.99.

I tried casting rand() to a float below, which didn't work. I'd still like to know the reason this didn't work.

saleAmount = ((float)rand() % 99950.00 + 50.00 ) / 100.00;

To make rand() a float with 2 decimal places, I did the following, which did work.

saleAmount = rand()*1.01;

I've also tried using fmod, however I can't figure out how to get the outcome between the 2 boundaries.

Any suggestions or helpful tips?

Thanks,

Miss Vavazoom

Edited by vavazoom: n/a

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by vavazoom
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.