Thread: Edit boxes and integers.

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    2

    Edit boxes and integers.

    I've been playing around with C++ for a few weeks and decided to jump into windows programming. I have created a simple program that calculates sales tax but have run into an issue.

    The program uses edit boxes in which the user inputs values for the starting price and their local tax rate and the results are outputed into a total tax box and a total prce box (using SetDlgItemInt). The edit boxes seem to ignore the decimal points on the tax rate box. The total tax box always returns 0, but works fine if I use a number >0.

    I've looked around on these forums but I'm having a hard time figuring out what I need to do. I found references to a sprintf and atof , but the atof function appears to be for strings to floats/doubles. Something that would take a float and make it into a string might help.

    I'll post the code if neccesary, and I'm using Dev-cpp 4.9.9.2.

    Thanks in advance

  2. #2
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Found this in less than 3 minutes of googling: http://www.cplusplus.com/ref/cstdlib/fcvt.html It says "Convert floating point value to string." as the description of what the function does, that's what you want right?
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    sprintf() is a more portable way to convert a float to a string.
    Code:
    char buff[32];
    float f = 1.5f;
    sprintf(buff,"%f",f);
    printf("the value of f is %s\n",buff);

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    2
    Both ways appear to work, but I like the sprintf way better!
    Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Edit Boxes Question
    By Ruben in forum Windows Programming
    Replies: 2
    Last Post: 09-14-2001, 12:06 AM
  2. Edit Boxes Question
    By RubenJ in forum Windows Programming
    Replies: 1
    Last Post: 09-12-2001, 08:01 PM