cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
Multiplying decimals
Multiplying decimals
Sep 30, 2012 at 5:54am UTC
ajung90
(2)
I'm trying to multiply a decimal number with an integer.
C++ keeps rounding up my decimal before multiplying, therefore resulting in an integer answer when i want a decimal answer.
Please help!
Thanks
Sep 30, 2012 at 6:21am UTC
Aramil of Elixia
(772)
u cant do decimals in an int try float
Sep 30, 2012 at 6:31am UTC
degausser
(78)
Instead of using int, use either double or float.
Sep 30, 2012 at 7:49am UTC
Akshit
(196)
1)use type cast
2)if you are saving the result in a variable then use float or double.
Sep 30, 2012 at 10:38pm UTC
ajung90
(2)
I put float instead of int, but it's still rounding it..
Sep 30, 2012 at 10:42pm UTC
closed account (
zb0S216C
)
ajung90
wrote:
"C++ keeps rounding up my decimal before multiplying"
A computer does not round: it truncates.
Post the expression that's giving the unexpected result; it saves the guess-work.
Wazzak
Topic archived. No new replies allowed.