Qt - custom decimal point and thousand separator

后端 未结 6 1851
野趣味
野趣味 2021-02-13 23:52

How can I convert a number (double) to string, with custom decimal point and thousand separator chars?

I\'ve seen QLocale, but I don\'t want to choose the localization c

6条回答
  •  南笙
    南笙 (楼主)
    2021-02-14 00:28

    Qt doesn't support custom locale. But to deal with just group and decimal point characters is trivial:

    const QLocale & cLocale = QLocale::c();
    QString ss = cLocale.toString(yourDoubleNumber, 'f');
    ss.replace(cLocale.groupSeparator(), yourGroupChar);
    ss.replace(cLocale.decimalPoint(), yourDecimalPointChar);
    

    BTW, spbots' question is not irrelevant. More detail about the goal always helps and it could lead to different approach that may serve you better.

提交回复
热议问题