Floating Point Issues - General Questions :: Discussion


4.We want to round off x, a float, to an int value, The correct way to do is?
A.y = (int)(x + 0.5)
B.y = int(x + 0.5)
C.y = (int)x + 0.5
D.y = (int)((int)x + 0.5)
Answer:  Option  A
Explanation:

Rounding off a value means replacing it by a nearest value that is approximately equal or smaller or greater to the given number.

y = (int)(x + 0.5); here x is any float value. To roundoff, we have to typecast the value of x by using (int)

Tutorial Link:
Published by:Michael Daani

Comments are not available

Post your comments here:

Optional

Date to Date Current Affairs 2022

PakMCQs.net

Quick Links

GAT Subject



   Computer Science    English Mcqs    Agriculture    

Engineering



   Computer Science    Civil Engineering    

Technical



   Networking    Electronics    Database    

Past Papers



   Model Papers    FPSC Papers