r/shittyprogramming • • Jun 28 '15

Embedded developer adventures

Post image
297 Upvotes

55 comments sorted by

View all comments

35

u/say_wot_again Jun 28 '15

But.... That's not what they meant when they said double! And how would you tell 1, 10, and 100 apart? I call shenanigans.

20

u/amphetamachine Jun 28 '15

Cast it as a string and pass it to atof

9

u/immibis Jun 28 '15

You mean like this?

int getRightPartOfDecimal(double d) {
    // XXX 2015-06-28 H.K. - /u/amphetamachine suggested this method to extract the second part of a double
    // XXX 2015-06-28 H.K. - Not sure why this needs an int cast in between though
    return atof((char*)(int)d);
}

1

u/amphetamachine Jun 29 '15

Oops, I guess all that higher-level programming has ruined me. By "cast as a string" I really meant sprintf(strval, "%f", floatval)