The number of type int in QString is converted to 3 digits of type QString, and the 3 digits are reserved

For example: For example, 1, I want to convert it to "001".

There are two ways:

method one:

int i=1;
QString b=QString("%1").arg(i, 3, 10, QChar('0'));

Among them, 3 means that 3 digits need to be reserved, 10 is decimal, and it is followed by 0.

Method Two:

int cmd=1;
QString str=QString::number(cmd).sprintf("%03d",cmd);


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324816351&siteId=291194637