Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

How to convert string to double ?

$
0
0
Ah sorry I misunderstood you, I thought you wanted to convert a string to a number, but if you want to add comma you want to convert a number to a string (numbers can’t have commas of course, so you need a string to display the number as a formatted string). :) It makes no sense to do something like text: parseFloat("20") because that will convert the string “20” to a float and then convert it back to a string “20”, which is the same as before obviously. there is no easy way of doing that I guess, you can maybe use a regular expression, I found this on stackoverflow [stackoverflow.com] it looks like a good solution: function numberWithCommas(x) {     return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); } or you can do it by yourself, split the string and add commas, but the result will be the same :) Edit: Just got an idea, maybe you can also use QLocale and Qt’s number formatting, since all you want is a thousand separator and QLocale::toString should be able to do that for you, but you need c++ for that, don’t think that can be done from QML.

Viewing all articles
Browse latest Browse all 4972

Trending Articles