boost::format
Hi all,
Im using boost::format to format a string like this
double tot_price = atof(Transamnt.c_str());
fmter.clear();
fmter = boost::format("%s %.2f");
fmter % "Belopp" % tot_price;
the problem is that in sweden the decimal point is ',' not '.' is there a way
to change that in the call to format,
i dont want to use find and replace
Regards
//huvcbo
#include <iostream>#include <locale>#include <boost/format.hpp>int main() { std::locale swe( "Swedish" ); std::locale::global( swe ); // <--- maybe supposed to throw a std::cout.imbue( swe ); in here too // no effect under VS8, and locales are my weak point in terms of // standard library knowledge. std::cout << boost::format( "%s %.2f", swe ) % "Belopp" % 123456.789 << std::endl;}
Belopp 123 456,79Press any key to continue . . . _
HTH
By the way, since you are using boost::format, you don't need to muck about with atof or similar functions. Just use boost::lexical_cast:
Although I wonder why you are storing an amount as a string.
jfl.
boost::format( "%s %.2f" ) % "Belopp" % boost::lexical_cast< float >( Transamnt );
Although I wonder why you are storing an amount as a string.
jfl.
Im working whith IPOS pay terminals and according to the protocol the
format on the amount is a string value.
//huvcbo
format on the amount is a string value.
//huvcbo
When does the terminal expect a string? You may be better off storing the value as a floating-point or integer value and converting to a string representation when you need it.
What is IPOS?
jfl.
What is IPOS?
jfl.
IPOS is a 'Intergrated Poin of Sale' an interface between a till 'ECR' and a pay terminal.
the interface receive the amount as currency value and the terminal is expecting
a xml transaction and the amount tag is a string value.
// huvcbo
the interface receive the amount as currency value and the terminal is expecting
a xml transaction and the amount tag is a string value.
// huvcbo
Quote:Original post by Ahnfelt
Boost: A shining example of why you shouldn't allow operator overloading.
?
Quote:Original post by huvcbo
IPOS is a 'Intergrated Poin of Sale' an interface between a till 'ECR' and a pay terminal.
the interface receive the amount as currency value and the terminal is expecting
a xml transaction and the amount tag is a string value.
// huvcbo
In that case, why do you even convert the string to a float? Do you need to manipulate it?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement