🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Int to Float conversion

    Scheduled Pinned Locked Moved UIFlow
    7 Posts 3 Posters 6.8k Views 1 Watching
    Loading More Posts
    • 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.
    • E Offline
      elettronico
      last edited by

      Hello, how can I convert an int value (10000 mV) from a variable to a float value in a Label block (10,000 V) ?
      Thank you all for the help

      1 Reply Last reply Reply Quote 0
      • C Offline
        Cognitive5525
        last edited by Cognitive5525

        What language?

        In Python you can simply:

        my_val = 10000
        my_val = my_val/1000

        1 Reply Last reply Reply Quote 0
        • C Offline
          Cognitive5525
          last edited by

          Since you posted under UIFlow, then that is what you use I suppose:
          0_1682692755877_c177659d-a376-4ab0-9568-04487becf4bd-image.png
          which results in the following Python code:

          my_val = my_val / 1000

          1 Reply Last reply Reply Quote 0
          • E Offline
            elettronico
            last edited by

            thank you Cognitive5525, I have already tried but it does not work.

            Here is the partial code:

              A3 = (str((hex(A2)[2:] + hex(A1)[2:])))
              A4 = (str(int(A3, 16))) // here all ok and the Label shows 10000 mV
              A5 = A4 / 1000
              label0.setText(str(A5)) //the label shows nothing
            
            C 1 Reply Last reply Reply Quote 0
            • C Offline
              Cognitive5525 @elettronico
              last edited by

              I'm not sure what A3 becomes since I can't see what A1 and A2 are, but:

              A4 = (str(int(A3, 16)))

              makes A4 a string which you can't do arithmetic on.

              Provided that A3 can be converted to an integer, I would:

              A4 = int(A3, 16)
              A5 = A3 /1000
              label0.setText(str(A5))

              1 Reply Last reply Reply Quote 0
              • E Offline
                elettronico
                last edited by

                @cognitive5525 said in Int to Float conversion:

                A4 = int(A3, 16)
                A5 = A3 /1000
                label0.setText(str(A5))

                Thank you!

                solved with this code:

                A4 = int(A3, 16)
                A5 = A4 /1000
                label0.setText(str(A5))

                1 Reply Last reply Reply Quote 0
                • ajb2k3A Offline
                  ajb2k3
                  last edited by

                  Use the math function block to convert in to float then use a text block to convert to string?

                  UIFlow, so easy an adult can learn it!
                  If I don't know it, be patient!
                  I've ether not learned it or am too drunk to remember it!
                  Author of the WIP UIFlow Handbook!
                  M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

                  1 Reply Last reply Reply Quote 0

                  Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                  Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                  With your input, this post could be even better 💗

                  Register Login
                  • First post
                    Last post