How can i convert qstring to money format ?
Ex: 1234567.89 = 1,234,567.89
How can i convert qstring to money format ?
Ex: 1234567.89 = 1,234,567.89
Last edited by newermind; 18th May 2009 at 13:04.
float QString::toFloat ( bool * ok = 0 ) const
i try to seperate with comma`s.
toFloat function is not worked.
Example
QString money = 1234.00
i try to
money = 1,234.00
How can i do it with using toFloat function?
newermind (18th May 2009)
Try this:
double dValue = 123467.99;
QString sValue = QString("%L1").arg(dValue ,12,'f',0,' ');
Actual question that i wanna ask is that, I have a QLineEdit, and when user enter some number into it, i want to replace that string with its currency represantation.
I tried to change the input on textChanged(const QString&) signal on that QlineEdit object, but i had involved lots of problems.
IMHO, There must be easy way to tell QLineEdit, use that locale to change numbers into currency.
I would try to make my own validator (derived from QValidator) that will check if with some regexp if line edit contains appriopriate value and fix it/change it to the currency format (QValidator::fixup()).
I would like to be a "Guru"
Useful hints (try them before asking):
- Use Qt Assistant
- Search the forum
If you haven't found solution yet then create new topic with smart question.
if I'm looking on a lineedit in the qt creator one of it's properties is the inputmask,
I think that it's what you're looking for.
http://doc.trolltech.com/4.3/qlineed...inputMask-prop
Wow old thread but I have some solutions.
So the problem is this you are going to have to change the text from your lineEdit to a QString object to use a similar myVariable.toDouble function.
Lets say I have a lineEdit called total_lineEdit. I would try this.
QString myString;
myString=ui->total_lineEdit->text ();
myString.toDouble ();
ui->total_lineEdit->setText (myString);
The problem I have is I need to setPrecision but looking for a QT version of this. I'm just learning C++ and QT at the same time and it does get confusing.
Qt Code:
QString myString; myString=ui->total_lineEdit->text (); myString.toDouble (); ui->total_lineEdit->setText (myString);To copy to clipboard, switch view to plain text mode
How is this a "solution"? Do you understand that your code does absolutely nothing to the string or the line edit contents? Line 1 declares a temporary QString instance. Line 2 retrieves the text into that string. Line 3 converts the string contents to a double, then throws the double away. Line 4 puts the unmodified string back into the line edit. Obviously, you are confused.
So what I am assuming you want to do is something like this: The user enters a string "1234.5" and you want it displayed with two digits of precision after the user is done: "1234.50". Then in your slot that handles the QLineEdit::editingFinished() signal, you could do something like this:
Qt Code:
void MyWidget::onEditingFinished() { bool didItWork; double dValue = myString.toDouble( &didItWork ); if ( didItWork ) // didItWork would be false if the string couldn't be converted. What if the user didn't enter a number? { ui->lineEdit->setText( myNewString ); } }To copy to clipboard, switch view to plain text mode
Look at the documentation for the QString::arg() version that takes a double as the first argument for an explanation of the formatting arguments.
Bookmarks