I have the folowing example :
double x = 2.5;
int n = (int)x;
int k = (int) floor(x);
Does casting double to int returns the round down number? or I should use floor function?
Be careful with negative numbers. Casting will truncate towards 0. floor
will truncate towards negative infinite.
If the value is positive, then both methods return the same truncated value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With