Thread: How to create floats from const char* ?

  1. #1
    Registered User
    Join Date
    Sep 2014
    Posts
    121

    How to create floats from const char* ?

    Hello,
    I know it sounds trivial question but I need to convert a string literal like "2222111.50" to floating point number. atof() fails me. It returns 2222111 and discards the .50? I`ve concat a 'f' to the end but it`s the same. Any ideas. Also I know the string is weird, but that`s the data.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Post the smallest and simplest compilable program that demonstrates the problem.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Sep 2014
    Posts
    121
    It was my misstake, using qDebug() which did not display values correctly. fprintf() shows right conversion. Sorry.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Create vector of floats in a for-loop
    By fclopez in forum C++ Programming
    Replies: 45
    Last Post: 01-07-2013, 01:24 PM
  2. Replies: 4
    Last Post: 04-20-2011, 01:19 PM
  3. Replies: 3
    Last Post: 11-15-2009, 04:57 AM
  4. Difference between const char * and char const *
    By explorecpp in forum C Programming
    Replies: 4
    Last Post: 08-09-2008, 04:48 AM
  5. Replies: 7
    Last Post: 04-28-2008, 09:20 AM

Tags for this Thread