boost::format

Started by
10 comments, last by huvcbo 16 years, 11 months ago
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
Advertisement
#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 . . . _


Okay HTH
Thanks!!!
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:

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
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.
Boost: A shining example of why you shouldn't allow operator overloading.
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
Quote:Original post by Ahnfelt
Boost: A shining example of why you shouldn't allow operator overloading.


?

Beginner in Game Development?  Read here. And read here.

 

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