Thread: Variable Type issue

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    162

    Variable Type issue

    Hi

    Is there a function similar to "SetDlgItemInt()" which is able to work with non integers (decimals)?

    Apparently SetDlgItemInt() is not required for float or double types, what do you recommend?

    Thank you

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Convert data to string, use SetDlgItemText. To convert data to a string, you can use sprintf.
    Last edited by Elysia; 02-11-2008 at 12:32 PM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    You could use SetDlgItemText() - then just create the text that you want to see.

    gg

  4. #4
    Registered User
    Join Date
    Apr 2007
    Posts
    162
    Ok That was actually my solution before... I can stick to that

    But In that case I have problems with determination of number of decimals...
    The program does not determine the decimals on its own so I have to do sprintf(char*, "%.*f", iDecimalPlaces, iInteger);

    Do you have a solution for this?
    Last edited by Gordon; 02-11-2008 at 01:01 PM.

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    sprintf() is what I would use

    gg

  6. #6
    Registered User
    Join Date
    Apr 2007
    Posts
    162
    Sorry still donīt get it... Just tried a few possibilities but all failed...

    This is one of them sprintf(chTotal, "%f", iTotal);

    Seems like sprintf always return 6 decimals even if they are equal to NULL.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Well, you can limit it to a fix number of decimals through
    sprintf(chTotal, "%0.2f", iTotal)
    This will only use two decimals.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User
    Join Date
    Apr 2007
    Posts
    162
    Yes that is actually my problem...
    I need a function that determines for me number of decimals of the double type.
    Then I use the returned value as you did

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    But the thing is that it will convert all decimals into a string, unless you specify otherwise.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Registered User
    Join Date
    Apr 2007
    Posts
    162
    All right

    What else do you recommend me. I agree this is not the best solution in this case

  11. #11
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    The number of decimal points to show is completely up to you. What does the value represent? A measurement? Money?

    Are you looking for locale dependant information - like the number of decimal points to show for a money value?

    gg

  12. #12
    Registered User
    Join Date
    Apr 2007
    Posts
    162
    I am creating a little calculator... So I need my answers to be in correct count of decimals...

    If I process 1/8 it should return 0.125 not 0.125000 or 0
    Sorry I did not state that its for calculator use before

  13. #13
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Just pass %f, and it will print any available decimals.
    Beware that floating points in somewhat inaccurate, so 1/8 can also return 0.12500001 or something. Don't know if it can happen to this particular equation, but it can happen to certain ones.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #14
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    1/8 is integer - that's why it is 0

    use 1.0/8 or 1/8.0
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  15. #15
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    What Every Computer Scientist Should Know About Floating-Point Arithmetic

    End the end, if you want exact precision - use a 3rd party library like GMP.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Conversion of pointers to functions
    By hzmonte in forum C Programming
    Replies: 0
    Last Post: 01-20-2009, 01:56 AM
  2. Replies: 6
    Last Post: 04-10-2008, 11:49 PM
  3. strings Vs. Char pointers
    By aijazbaig1 in forum C Programming
    Replies: 49
    Last Post: 02-13-2008, 09:51 AM
  4. "Deciding" in runtime the type of a variable
    By mikahell in forum C++ Programming
    Replies: 28
    Last Post: 07-22-2006, 09:51 AM
  5. Difference between 'data type' and variable?
    By cdalten in forum C Programming
    Replies: 2
    Last Post: 02-02-2006, 08:48 AM