Index: applets/calculator/package/contents/ui/calculator.qml =================================================================== --- applets/calculator/package/contents/ui/calculator.qml +++ applets/calculator/package/contents/ui/calculator.qml @@ -118,7 +118,7 @@ operand = operand * 10 + digit; - displayNumber(operand / Math.pow(10, decimalsOperand)); + displayNumber(operand, decimalsOperand); showingInput = true; ++inputSize; } @@ -204,7 +204,7 @@ return; } - displayNumber(result/Math.pow(10, decimalsResult)); + displayNumber(result, decimalsResult); showingInput = false; } @@ -237,7 +237,7 @@ function clearClicked() { clearOperand(); operator = ""; - displayNumber(operand); + displayNumber(operand, 0); showingInput = true; showingResult = false; } @@ -253,9 +253,48 @@ Math.floor(Math.log(Math.abs(number))/Math.log(10)) + 1; } - function localizeNumber(number) { - return number.toString().replace(".", Qt.locale().decimalPoint); - } + function toStringAndlocalizeNumber(number, decimals) { + var text = ""; + + if(number.toString().charAt(0) === "-") + { + text += number.toString().charAt(0); + number = number * -1; + } + + var point = number.toString().length - decimals; + + var i = 0; + + for(i; i < point; ++i) + { + text += number.toString().charAt(i); + } + + if(i == number.toString().length) + { + return text; + } + + if(i && point > 0) + { + text += Qt.locale().decimalPoint; + } + else + { + text += "0" + Qt.locale().decimalPoint; + for(var j = 0; j < point * -1; ++j) + { + text += "0"; + } + } + for(i; i < number.toString().length; ++i) + { + text += number.toString().charAt(i); + } + + return text; + } // use the clipboard datasource for being able to inspect the clipboard content before pasting it PlasmaCore.DataSource { @@ -296,8 +335,8 @@ return new RegExp('^[0-9]*[\.,]?[0-9]+$').test(input); } - function displayNumber(number) { - display.text = localizeNumber(number); + function displayNumber(number, decimals) { + display.text = toStringAndlocalizeNumber(number, decimals); if (display.length > maxInputLength) { display.text = localizeNumber(convertToScientific(number, 14));