# Thread: displaying float digits

1. ## displaying float digits

Hey there, i'm curious on how to display the first and rightmost digit of the integral portion of a floating point integer. I'm not quite sure how to do this.

whould I create a two variables like so:

float floatintPointInt;
float result;

....

result = floatingPointInt % floatingPointInt / 10;

....

Thanks

2. Code:
`int result = (int)floatingPointInt % 10;`

3. Thanks a lot man.

4. Hi, i'm sorry.. I'm not quite sure what is wrong with my code.
It's supposed to print the first and the second rightmost digit of the integral portion of the float.

Code:
```int main()
{
float decimal = 0.0;
int result = (int)decimal % 10;

printf("Floating point Int: ");
scanf("%f", result);

printf("\n\n%f", result);

return 0;
}```

I'm not sure if i should assign the "decimal" to 0.0.. when i don't the compiler give an error.

thank you.

5. >I'm not sure if i should assign the "decimal" to 0.0.. when i don't the compiler give an error.
An error? Or a warning that you are using the value of 'decimal' before it has been initialized?

>scanf("%f", result);
Here scanf expects a pointer to a float -- give it one.
Code:
`scanf("%f", &decimal);`
Convert the float 'decimal' to the int 'result' after you've gotten 'decimal'.

>It's supposed to print the first and the second rightmost digit of the integral portion of the float.
You may want to use % 100.

>printf("\n\n%f", result);
Use %d with an int.
Code:
`printf("\n%d\n", result);`

6. Oh geeeezzz.. man.. thank you so much.

I can't believe i missed that scanf("%d", &result);........... bahhh

Thank you

Popular pages Recent additions