Thread: Only decimal values

  1. #1
    Registered User
    Join Date
    Aug 2015
    Posts
    7

    Only decimal values

    I will give a value like 25.2563 But the output should be like 2563

    there should be no point. it should only display the numbers after point ?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Read the input as a string and then extract the substring consisting of the characters after the '.'.

    If you must accept the input as a float or double, then you need to decide how many decimal places you want.
    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
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    You could print the value in a buffer with sprintf, for example, and then use sscanf to parse the data you want to use.
    Devoted my life to programming...

  4. #4
    Registered User
    Join Date
    Aug 2015
    Posts
    7
    Explain me in detail ?

  5. #5
    Registered User
    Join Date
    Aug 2015
    Posts
    7
    Quote Originally Posted by laserlight View Post
    Read the input as a string and then extract the substring consisting of the characters after the '.'.

    If you must accept the input as a float or double, then you need to decide how many decimal places you want.
    program please ? i will understand .. dont mind ty

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    No, I am not going to do your homework for you. Attempt something first.
    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

  7. #7
    Registered User
    Join Date
    Aug 2015
    Posts
    7
    how can i enter '.' ? in string the only character to be entered is '_'

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Karthik Datta
    how can i enter '.' ? in string the only character to be entered is '_'
    What is the code that you wrote such that you found that you have this 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

  9. #9
    Registered User
    Join Date
    Aug 2015
    Posts
    7
    Quote Originally Posted by laserlight View Post
    No, I am not going to do your homework for you. Attempt something first.
    how can i enter '.' ? in string the only character to be entered is '_'

  10. #10
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Quote Originally Posted by Karthik Datta View Post
    how can i enter '.' ? in string the only character to be entered is '_'
    Your question is not clear. Please try to explain what you mean in more detail.

  11. #11
    Registered User
    Join Date
    Aug 2015
    Posts
    7
    Quote Originally Posted by Matticus View Post
    Your question is not clear. Please try to explain what you mean in more detail.
    Please write a small sample program to read decimal number into string and print it out ? i am not getting it

  12. #12
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Post your attempt (in code tags) so we can help you fix whatever problems you're having.

  13. #13
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Karthik Datta
    Please write a small sample program to read decimal number into string and print it out ? i am not getting it
    Please write a small program to read a string and print it out.
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 06-27-2015, 08:34 AM
  2. Replies: 13
    Last Post: 07-27-2013, 10:20 AM
  3. Possible to print float values without decimal point ?
    By Krabiki in forum C Programming
    Replies: 2
    Last Post: 04-08-2013, 03:39 AM
  4. Replies: 10
    Last Post: 06-12-2002, 03:15 PM
  5. decimal to binary, decimal to hexadecimal and vice versa
    By Unregistered in forum C++ Programming
    Replies: 9
    Last Post: 12-08-2001, 11:07 PM