I've confused myself and forgot how to do this. I want to take a floating input, multiply it by 100, and then change it to an integer without rounding.
ie: 650.127 = 65012 23.3 = 2330 45.01 = 4501
#include < stdio.h > void main(){ double input; scanf("%e", &input); printf("%e\n", input); int g=(input*100); printf("new input is %d\n", g); if(input<=0) printf("No input");}
1.057003e-307new input is 0
#include < stdio.h > void main(){ double input; input = 650.23; printf("%e\n", input); int g=(input*100); printf("new input is %d\n", g); if(input<=0) printf("No input");}
3/16/2011 11:49:59 AM
[EDIT]I changed the following because I realize I was using exponential form and I meant not to.scanf("%f", &input);printf("%f\n", input);
3/16/2011 12:20:41 PM
Figured it out (after scratching my head for about an hour on this ) nm[/thread].[Edited on March 16, 2011 at 12:28 PM. Reason : .]
3/16/2011 12:28:02 PM
so you gonna share your solution then?
3/16/2011 1:29:53 PM
I think scanf needs %lf for the double. The following seems to work:#include <stdio.h> int main(){ double input; scanf("%lf", &input); printf("%f\n", input); int g=(input*100); printf("new input is %d\n", g); if(input<=0) printf("No input"); return 0;}
3/16/2011 1:38:29 PM
^^ dakota_man posted it.Works perfectly. After writing a few functions, tons of if/else statements, I brain farted over simple syntax [Edited on March 16, 2011 at 2:19 PM. Reason : .]
3/16/2011 2:18:46 PM
well at least you didn't post this on StackOverflow
3/16/2011 2:26:40 PM
Any particular reason you can't explicitly type cast (and then output if thats ultimately what you are trying to do)?
3/16/2011 5:33:14 PM
because I'm a n00b, learning C, and this is for a project for my ece 220 class.
3/16/2011 7:53:17 PM
they teach C in 220 now?
3/16/2011 8:30:26 PM
my first thout was to cast also, something like (int)(100*input)
3/16/2011 8:30:38 PM
3/16/2011 8:48:42 PM
3/17/2011 12:31:21 AM
I meant 209. My bad
3/17/2011 9:50:52 AM