Qt locale formatting of large currency (or number) on linux - c++

I am trying to format a number as a currency and having problems. I've tried with both the default locale and a specific one (like below). The number is formatted in scientific notation nonetheless.
QLocale::setDefault( QLocale(QLocale::English, QLocale::UnitedStates) );
reportCost->setText( QString("$%L1").arg( cost ) );
The trouble is that as soon as I hit millions I get numbers like $1.6473e6 rather than $1,647,312. How can I fix this?
Also,is there really no way to format a currency at all in Qt, like positioning the symbol and proper negative representation?
I cannot test on Windows right now so I don't know if this is Linux specific.

Unfortunately, the current implementation of QLocale falls short in a lot of these areas. See "QLocale: It’s about time (and dates, and languages, and …)" for an explanation of where this is headed in the future.
For now, a quick-and-dirty solution would be:
QString("$%L1").arg(amt, 0, 'f', 2);
If you need real localization, the ICU libraries might be helpful.

I know that this is an old question, but it's worth pointing out to anyone who stumbles across this that in Qt 4.8 and above, the first thing to try should be QLocale::toCurrencyString(...)

Related

How to change the value of wxDatePickerCtrl?

I have tried this, But I am not able to get date displayed on the datePickerCtrl.
Here SDOB is a wxDatePickerCtrl.
SDOB->SetValue(Rs.GetDate(3));
But I am able to get the date onto a label or text field by doing
wxStaticText11->SetLabel(Rs.GetDate(3).FormatDate());
But for my purpose I would like to get it onto the datePickerCtrl itself. Help!
Also where can I find good documentation with examples for wxWidgets? I am a beginner.
You're using the correct function for setting wxDatePickerCtrl value, so if you don't see what you expect, the date you pass to it must be invalid or otherwise different from what you think it is. Generally speaking, when asking about why something doesn't work you should explain both how do you expect it to work and what actually happens because otherwise nobody else can know what's really going on.
The documentation for this control is at https://docs.wxwidgets.org/3.1.4/classwx_date_picker_ctrl.html as could be expected and there are a hundred of examples distributed with wxWidgets, so if you want to see an example of this class in action, I recommend doing grep -lR wxDatePickerCtrl samples in the directory containing wxWidgets sources.
Good luck!

Format thousands separator

I am programming in c++ using mfc in visual studio 2010.
I live in Europe, so I have the regional settings of the PC not USA but Europe.
I use the .Format function of CString to print the result of a calculation and I want to add a decimal point as separator between hundred and thousands.
For example, I would like to have displayed 23.400 instead of 23400
Is it possible using a particular formatting of % or i have to change the setting of the pc?
Thanks for the help
As far as I know CString's .Format doesn't support this.
I'd use a stringstream to handle the formatting:
std::ostringstream temp;
temp.imbue(std::locale(""));
temp << 23400;
CString result = temp.str().c_str();
Specifying an empty string as the name of the locale as I've done here means it should pick up the locale setting from the OS. You can give the name of a specific locale instead (e.g., if you want a specific locale, regardless of how the OS is configured):
temp.imbue(std::locale("de")); // German locale
As far as I know this is what your are looking for. Simple search on google gave the answer. This type of print (%.2f) by the way is pretty standard among pretty much every modern language.
"Floating point: %.2f\n"
https://msdn.microsoft.com/en-us/library/aa314327(v=vs.60).aspx

Room-saving alternative for QR-Codes?

I am looking for a way to encode 100 byte on paper and hope to find a more room-saving way to do this than QR-Codes.
Now this may sound a little strange, as the information needs room, but e.g. something wider and less tall would be cool.
Any suggestions?
(Also, C++ libraries would be nice.)
EDIT: Keep in mind I need to be able to scan it again. Thanks. :)
There are loads of different types of barcode out there - http://en.wikipedia.org/wiki/Barcode pick any one.
Why not just print the data as a base64 string:
Base64
Should be plenty of freely available libraries to handle the conversion and each 100 byte piece of data would be 34 characters. You could use as small a font as you liked and it fits very nicely with your wider and less tall requirement.
There is a software out there that prints source-code as tiny dots at 600dpi and is then able to convert it back. Maybe you could do that. (Bit its pretty much just printing the QR code smaller)

Create And Convert To PDF's.. NO Toolkit

Not sure where else to ask this, so I figured I'd give good old stackoverflow a shot.
Let's say, by chance, I would like to write a library or set of libraries that will create PDF's and convert files to PDF, AND I could care less about how long it will take me to complete (3 months - 10 years.. whatever). I have absolutely no interest in paying for a toolkit... the point of this would be to learn how to manipulate and create files like PDF's. There's nothing business critical about the project, I just want to learn how to do it. Where do I start? I would imagine something like this would be written in C++, but I'm not sure... maybe high level languages would work as well. I'm not looking for someone to tell me exactly how to do it, but send me in the write direction, or at least point out the concepts I would need to concretely grasp before proceeding with such a project.
Any advice and help in directing me here is greatly appreciated : )
Well, you will need a very good understanding of the PDF file format. Adobe publishes the standard and you can start at their site. You can start with the base 1.7 standard and then read the cumulative supplements from there. It is a daunting task, but it can be done and you can pretty much use any language you want, because in the end you are just generating bytes that can be saved to a file.
If you want to convert from, let's say, word documents, it will get a little trickier. Microsoft has published their file formats, which you would have to learn and then learn how to translate that into the corresponding PDF formatting. Also note that the .doc and .docx formats are completely separate file formats and would require separate engines to convert them.
With unlimited time, it is definitely doable, you would just need to ask yourself if it is worth it.

Reed-Solomon Decoding

I've got a sequence of 28 bytes, which are supposedly encoded with a Reed-Solomon (28, 24, 5) code. The RS code uses 8-bit symbols and operates in GF(28). The field generator polynomial is x8+x4+x3+x2+1. I'm looking for a simple way to decode this sequence, so I can tell if this sequence has errors.
I've tried the Python ReedSolomon module, but I'm not even sure how to configure the codec properly for my RS code (e.g. what's the first consecutive root of the field generator polynomial, what's the primitive element). I also had a look at Schifra, but I couldn't even compile it on my Mac.
I don't care too much about the platform (e.g. Python, C, Scilab) as long as it is free.
I successfully built an embedded data comms project that used Reed Solomon error correction a few years ago. I just had a look at it to refresh my memory, and I found that I used a fairly lightweight, GPL licenced, C language subsystem published by a well known guy named Phil Karn to do the encoding and decoding. It's only a few hundred lines of code, but it's pretty intense stuff. However I found I didn't need to understand the math to use the code.
Googling Phil Karn Reed Solomon got me this document.
Which looks like a decent place to start. Hope this helps.