import QtQuick 2.10 Rectangle { border.color: "#319c00" Text {id: result } function textFromValue(text) { var re = new RegExp("\\.0*$|(\\.\\d*[1-9])(0+)$"); text = text.replace(re, "$1"); // <-- this breaks in Qt 5.12.2 // Workaround for 5.12.2 // var ex = re.exec(text); // if (ex) text = text.replace(ex[0], ex[1] || ""); return text; } function _print(res) { result.text = result.text + res + "\n"; } Component.onCompleted: function() { _print(textFromValue("123")); _print(textFromValue("123.00")); _print(textFromValue("123.0")); _print(textFromValue("123.")); _print(textFromValue("123.50")); _print(textFromValue("123.05")); _print(textFromValue("0.050")); }; }