Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [solved]Why Number function sometimes gets some unpredictable real parts?
Forum Updated to NodeBB v4.3 + New Features

[solved]Why Number function sometimes gets some unpredictable real parts?

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    owenzhao
    wrote on last edited by
    #1

    I am using javascript Number function to convert string to real from textField.text. I have made to textField.text can only accept number like 80.3 which mean only have 1 decimal from the decimal point.

    However, I find sometimes the conversion is not always what I want. For example, when I input 80.2 in the textField, the conversion is 80.2. However, when I input 88.7, I will get 88.69999694824219.

    So I have to use Math.round() to deal with what Number() gets.

    My question is, is that Number() are always not trustable that we should always use a round() dealing with it? I also want to know why this happened?

    1 Reply Last reply
    0
    • O Offline
      O Offline
      owenzhao
      wrote on last edited by
      #2

      I find this. http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html =.=||

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mlong
        wrote on last edited by
        #3

        That is a good reference. Thanks for the link!

        Software Engineer
        My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved