在 QLabel 上将 12digit double 或 int 显示为 full 而不是 3.23223e+9 [英] Display 12digit double or int as full instead of 3.23223e+9 on QLabel

查看:73
本文介绍了在 QLabel 上将 12digit double 或 int 显示为 full 而不是 3.23223e+9的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C++ 在 QLabel 上将数字 3232235975 显示为 3.23223e+9,而在 QCustomPlot 轴上显示为3.23223*10^9.我不涉及诸如 std::cout 之类的流,这就是为什么 std::setprecision 不适用于我的情况.

C++ is displaying a number 3232235975 on QLabel as 3.23223e+9, while on QCustomPlot axis as 3.23223*10^9. I am not involving stream such as std::cout, that is why std::setprecision doesn't work for my case.

我实际上正在使用 QCustomPlot 绘制轴上带有 12 位数字的图形.这是 C++ 问题还是 QCustomPlot 机制问题?如何显示号码的所有数字?

Am actually working with QCustomPlot to plot graph with 12digit numbers on the axis. Is this C++ issue or is it QCustomPlot mechanism issue? How can I display all the digits of the number?

谢谢

在收到@saeed 的setNumberPrecision() 提示后,现在协调仍然以2.88798e+9 格式显示.现在轴已经显示 4000000000,我希望坐标 QLabel(如我附上的图片所示)也显示 2887984335.

After receiving hint of setNumberPrecision() from @saeed, now the coordination is still showing in 2.88798e+9 format. Now that the axis is already showing 4000000000, I want the coordination QLabel (shown in the image I attached) also display 2887984335.

我正在协调并将其设置为这样的 QLabel.

I am getting the coordination and setting it to a QLabel like this.

double x2 = ui->widget_graph2->xAxis->pixelToCoord(_mouseEvent->pos().x());
double y2 = ui->widget_graph2->yAxis-pixelToCoord(_mouseEvent->pos().y());
ui->label_xcoord_2->setNum(x2);
ui->label_ycoord_2->setNum(y2);

我正在像这样使用 setData() 设置绘图数据

And I'm setting the plot data using setData() like this

QVector<double> x2(i), y2(i);
for(int o = 0; o <= i; o++){
    double dSec = arrayIPxTime[o][0] - startSecond;
    double dMin = dSec/60;
    double ipv4addr = arrayIPxTime[o][1];
    x2[o] = dMin;
    y2[o] = ipv4addr;
}
ui->widget_graph2->addGraph(0);
ui->widget_graph2->graph(0)->setData(x2, y2);
ui->widget_graph2->installEventFilter(this);

推荐答案

以您想要的格式显示坐标

To display coordinates in your wanted format

ui->label_xcoord_2->setNum(x2);
ui->label_ycoord_2->setNum(y2);

对QLabel使用void setText(const QString &)方法并通过

Use void setText(const QString &) method for QLabel and pass

QString QString::number(double n, char format = 'g', int precision = 6)

作为您想要的格式和精度的参数:

As parameter with your wanted format and precision:

格式含义

e 格式为 [-]9.9e[+|-]999

e format as [-]9.9e[+|-]999

E 格式为 [-]9.9E[+|-]999

E format as [-]9.9E[+|-]999

f 格式为 [-]9.9

f format as [-]9.9

g 使用 e 或 f 格式,以最简洁的为准

g use e or f format, whichever is the most concise

G 使用 E 或 f 格式,取其最简洁

G use E or f format, whichever is the most concise

这篇关于在 QLabel 上将 12digit double 或 int 显示为 full 而不是 3.23223e+9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆