From: Christian S. <sti...@tu...> - 2002-09-24 09:48:06
|
Martin Preuß wrote: >>6894c6894 >>< value="-49,57:EUR" >> > > Ok, das liegt an dem neuen Value-Handling von Fabian (?). Da werden die > Nachkommastellen IMMER addiert, ohne das Vorzeichen zu beruecksichtigen. Uns werden garantiert noch häufiger solche Probleme über den Weg laufen, und zwar so lange, wie wir versuchen, selber das Parsing String->Float zu machen. Ich hab folgenden Implementations-Vorschlag, wie wir (endlich) genau jenes Parsing der libc überlassen würden. Die eigentliche Umwandlung geschieht dann nur noch durch den Aufruf "ist >> _value". Meinungen? Wobei das natürlich nicht eilig ist. Wenn das funktioniert, kann das eingecheckt werden und halt in Zukunft die fehlerträchtige wir-parsen-das-selber-Implementierung ablösen. Christian Value::Value(const string &strvalue) :_value(0.00) ,_isvalid(true) { // find the seperator betw. value and currency unsigned int i = strvalue.find(":"); // extract currency if present if (i == string::npos) { _currency = ""; i = strvalue.length(); } else { // check for any malformed string-values if (strvalue.find_first_of(":") != strvalue.find_last_of(":")) throw Error("HBCI::Value::Value(string)", ERROR_LEVEL_NORMAL, 0, ERROR_ADVISE_RETRY, "Wrong string format (too many ':')."); _currency = strvalue.substr(i+1, 3); } // extract the value in a substring string vstring = strvalue.substr(0, i); // New stringstream to read the float value from istringstream ist(vstring); // Does this string hold one comma instead of decimal points? Then // force a switch of the locale to the German one. Otherwise, just // use the current locale. if (vstring.find(",") && (vstring.find_first_of(",") == vstring.find_last_of(","))) setlocale(LC_NUMERIC, "de"); // Read float (double) value, and throw HBCI::Error if that fails. if ( !(ist >> _value) ) throw Error("HBCI::Value::Value(string)", ERROR_LEVEL_NORMAL, 0, ERROR_ADVISE_RETRY, "Wrong string format (conversion string->float failed)."); } |