displaying float digits

This is a discussion on displaying float digits within the C Programming forums, part of the General Programming Boards category; Hey there, i'm curious on how to display the first and rightmost digit of the integral portion of a floating ...

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    8

    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. #2
    Registered User
    Join Date
    May 2003
    Posts
    148
    Code:
    int result = (int)floatingPointInt % 10;
    Last edited by Wledge; 10-06-2003 at 12:13 PM.

  3. #3
    Registered User
    Join Date
    Oct 2003
    Posts
    8
    Thanks a lot man.

  4. #4
    Registered User
    Join Date
    Oct 2003
    Posts
    8
    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. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    >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);
    Last edited by Dave_Sinkula; 10-09-2003 at 09:45 PM.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  6. #6
    Registered User
    Join Date
    Oct 2003
    Posts
    8
    Oh geeeezzz.. man.. thank you so much.

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

    Thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 05-13-2009, 03:25 PM
  2. Could somebody please help me with this C program
    By brett73 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 01:19 AM
  3. Display list not displaying?
    By psychopath in forum Game Programming
    Replies: 5
    Last Post: 09-19-2004, 06:47 PM
  4. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 04:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21