Jump to content
  • Advertisement
Sign in to follow this  
huvcbo

boost::format

This topic is 4146 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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,79
Press any key to continue . . . _


Okay HTH

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Im working whith IPOS pay terminals and according to the protocol the
format on the amount is a string value.
//huvcbo

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!