LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-11-2003, 03:11 PM   #1
ujotne
LQ Newbie
 
Registered: Sep 2003
Posts: 13

Rep: Reputation: 0
String fiddling


Hi,

I am looking for the a compact way of removing superfluous right hand zeros in C++. The task at hand is (double) numerical user input from a listbox. I want to first validiate the number (no problem with that) and then echo a possibly corrected value to the list box.

1) Only significant fractional digits should be shown; i.e right hand side zeros should be suppressed.
2) The number of significant fractional digits should be allowed to increase up to some max number.
3) If the user input from the list box contains more than the allowed number of fractional digits the echoed number should be rounded off (not truncated) to the max allowed fractional digits.

Although the necessary code isn't that complicated, it tend to be a bit long winded when all necessaray error checking is included. Hence, if anybody out there knows about a snipped that performs the above task, I would be interesting in having a look at it.

Regards
Udo.
 
Old 09-11-2003, 04:14 PM   #2
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
how about something like this
Code:
#include <iostream>
#include <sstream>
#include <string>

int main()
{
    std::string number="000343.5678000";
    double num=0;

    std::istringstream iss(number);
    iss >> num; 

    std::cout << num; 

    return 0;
}
~
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash way to tell if String is in String tongar Programming 3 06-16-2005 06:59 AM
C....Search a string for a string Scrag Programming 4 06-14-2004 04:15 PM
Fiddling with Menudrake (10.0 Community) Napper Mandriva 11 03-22-2004 04:53 AM
java test if string in string array is null. exodist Programming 3 02-21-2004 01:39 PM
fiddling with lilo.conf rvijay17 Linux - Newbie 3 02-24-2003 10:04 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration