Results 1 to 3 of 3

Thread: comma as decimal seperator

  1. #1

    Default comma as decimal seperator

    Hi, i got the problem with result when inputing numbers in 2 lineedits like:

    first line edit: 12,7
    secound line edit: 7,2

    and expect sum result in third one: 19,9 , but i get nothing becouse of comma as seperator. if i put numbers like 12.7 and 7.2 i get 19.9

    soo i wonder is there any solution to that... i rly don't care if result is 19,9 or 19.9 i just whanna make my qt calculate with dot and/or comma as decimal seperator...

    Thanks, and i hope i explain my problem well
    Last edited by Malisha100ka; 26th August 2015 at 19:56.

  2. #2
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    120
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: comma as decimal seperator

    Hello,

    if you take the input from a line edit you get a string, that needs to get translated into a double/float number. You can do that translation by yourself writing a suitable parsing function or you may use a locale with comma as decimal separator and apply QLocale::toDouble() to your string.
    An example:
    Qt Code:
    1. QLocale l(QLocale::German);
    2. double f = l.toDouble("12,2");
    3. std::cout << f << std::endl;
    To copy to clipboard, switch view to plain text mode 
    See http://doc.qt.io/qt-5.4/qlocale.html

    Best regards
    ars

  3. #3

    Default Re: comma as decimal seperator

    thanks!! big thanks!!

    i read that link few times before posting on forum and couldn't get it, but i understand it now from your explanation!

    it works perfectly!

Similar Threads

  1. how to add seperator into QMenuBar?
    By josentop in forum Qt Programming
    Replies: 1
    Last Post: 19th October 2011, 14:11
  2. how to add seperator in statusbar of widget?
    By banlinhtienphong in forum Newbie
    Replies: 3
    Last Post: 28th April 2011, 07:37
  3. remove seperator
    By navi1084 in forum Qt Programming
    Replies: 0
    Last Post: 4th March 2009, 05:05
  4. how to hide seperator in toolbar using Qt 2.3 NCE
    By Sandip in forum Qt Programming
    Replies: 0
    Last Post: 16th December 2008, 08:16
  5. QDoubleSpinBox: dot as comma
    By Raccoon29 in forum Newbie
    Replies: 4
    Last Post: 21st May 2008, 18:44

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.