Double and float | SoloLearn: Learn to code for FREE!

+5

Double and float

void Test(double d) {cout << "1";} void Test(float e) {cout << "2";} int main() { Test(1.0); // calls double function } I am not aware how to call Test from main for float... I mean to say what should be passed as value for float type function call...

3/16/2018 3:11:29 AM

Ketan Lalcheta

4 Answers

New Answer

+8

the compiler takes in double as default. Its good practice to specify floats as 2.03f with the f at the end of the number

+3

「HAPPY TO HELP」 true Double and float void Test(double d) {cout << "1";} void Test(float e) {cout << "2";} int main() { Test(1.0f); // calls float function }

+3

Man Ketan Lalcheta you can use float casting to if you are sure about calling function is passing float data. Test((float)1.0); // calls float function

+2

its better practice to forget about float and always use double. Internally java casts every float to a double and then converts them back anyway