在文本字段中截断"真实"值?

Gui*_*shy 0 floating-point qt text qml

我得到了以下代码:

property real compassValue : 3.1415927895412
Text {
    text: "<b>" + compassValue + "°</b>"
}
Run Code Online (Sandbox Code Playgroud)

事实是我只想显示"3.14".有没有办法截断这个值?

hid*_*bit 5

你可以简单地使用这个toFixed()功能:

property real compassValue : 3.1415927895412
Text {
    text: "<b>" + compassValue.toFixed(2) + "°</b>"
}
Run Code Online (Sandbox Code Playgroud)