Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Beginner's Question on Type Casting

I was going to use math.h on my numbers in my random number generator. It seems that I can only use the math.h functions on doubles. So:

I am trying to give "value" the value of "currentValue", or at least part of the number's value to be transferred over. I am working with a random number generator, so I do not care if the entire number is transferred. I only need part of it to work.

I have at some point:

int currentValue;
double value;

** Through code not shown their values are set. **

Later, I need part of value to go to currentValue.

currentValue = value 

I tried:

currentValue = static_cast<int>value; 

Any help would be appreciated.

Thanks for the help. The problem is solved.

like image 360
Guest Avatar asked Aug 01 '26 20:08

Guest


1 Answers

you forgot the parens:

currentValue = static_cast<int>(value); 
like image 71
justin Avatar answered Aug 03 '26 10:08

justin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!