Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Error/Bug
    4. Funktion formatValue in Beschriftung

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    UNSOLVED Funktion formatValue in Beschriftung

    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      BitCoder @paul53 last edited by

      @paul53
      Danke für die rasche Antwort. Ich bin zu blöd und verstehe deine Lösung nicht. Wie muss ich den String in der Beschriftung anpassen, dass es funktioniert?
      Im Moment sieht der Beschrifungsstring so aus:

      {hm-rpc.0.KEQ0579377.4.ACTUAL_TEMPERATURE} °C

      chrome_8pcdW2kZWu.png

      wo kommt nun das val.toFixed(0) hin?

      Gruss
      Tom

      paul53 liv-in-sky 2 Replies Last reply Reply Quote 0
      • paul53
        paul53 @BitCoder last edited by

        @BitCoder sagte:

        wo kommt nun das val.toFixed(0) hin?

        Mit Vis kenne ich mich leider nicht aus.

        1 Reply Last reply Reply Quote 0
        • liv-in-sky
          liv-in-sky @BitCoder last edited by

          @BitCoder

          habe es mit einem html widget probiert

          {vart:controll-own.0.AAATEST.TestString1; vart=Number(Math.round(vart*100)/100)}
          

          Image 1.png

          rundet einen teststring auf 2 stellen nach dem komma

          ice987 1 Reply Last reply Reply Quote 0
          • ice987
            ice987 @liv-in-sky last edited by ice987

            @liv-in-sky sagte in Funktion formatValue in Beschriftung:

            {vart:controll-own.0.AAATEST.TestString1; vart=Number(Math.round(vart*10)/10)} -> modifiziert

            dies hatte ich bereits in einem anderen Bezug versucht, die Ausgabe ist jedoch bei mehreren Nachkommastellen von vart x.x was funktioniert. Ist vart aber eine Zahl ohne Komastelle (z.b. 6), kommt als Ergebnis 6 statt 6.0 raus.

            @BitCoder möchte jedoch

            (...) einer permanenten Nachkommastelle (...)

            paul53 1 Reply Last reply Reply Quote 0
            • paul53
              paul53 @ice987 last edited by paul53

              @ice987 sagte:

              Zahl ohne Komastelle (z.b. 6), kommt als Ergebnis 6 statt 6.0 raus.

              Das ist generell bei Zahlen so. Eine permanente Nachkommastelle kann nur ein String darstellen. In Javascript gibt es dafür zahl.toFixed(1):

              1 Reply Last reply Reply Quote 0
              • liv-in-sky
                liv-in-sky last edited by liv-in-sky

                das funktioniert bei mir

                mit 6 =6.00
                oder 6.4445 = 6.45

                {v:controll-own.0.AAATEST.TestString1;(v/1).toFixed(2)}
                
                ice987 paul53 2 Replies Last reply Reply Quote 0
                • ice987
                  ice987 @liv-in-sky last edited by ice987

                  @liv-in-sky

                  das funktioniert!

                  v = 6: ergibt Ausgabe: 6.0
                  v = 6.123: ergibt Ausgabe: 6.1

                  Vielen Dank!

                  liv-in-sky 1 Reply Last reply Reply Quote 0
                  • liv-in-sky
                    liv-in-sky @ice987 last edited by

                    @ice987 gerne

                    https://forum.iobroker.net/post/247433

                    1 Reply Last reply Reply Quote 0
                    • paul53
                      paul53 @liv-in-sky last edited by paul53

                      @liv-in-sky
                      Damit es klarer ist, würde ich es so verwenden:

                      {val:hm-rpc.0.KEQ0579377.4.ACTUAL_TEMPERATURE;Number(val).toFixed(1)} °C
                      

                      Dass die Division durch 1 in eine Zahl wandelt, ist nicht für jeden gleich ersichtlich.
                      Anstelle von Number() kann auch parseFloat() verwendet werden.

                      B 1 Reply Last reply Reply Quote 2
                      • B
                        BitCoder @paul53 last edited by

                        Jetzt bin ich überwältigt, wie viele sich beteiligt haben, sich der Sache anzunehmen.
                        Die Variante von paul53 gefällt mir persönlich am besten. Das mit der Division war mir nicht klar, bis du das mit dem Cast erklärt hast.
                        Besten Dank. Es funktioniert jetzt so, wie ich mir das vorgestellt habe.

                        Trotzdem ist die Geschichte mit der Funktion formatValue(decimals) nicht gelöst. So wie es in der Dokumentation beschrieben ist, funktioniert es meines Erachtens nicht.

                        Gruss an alle Helfer
                        Tom

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post

                        Support us

                        ioBroker
                        Community Adapters
                        Donate

                        721
                        Online

                        31.9k
                        Users

                        80.1k
                        Topics

                        1.3m
                        Posts

                        bug iobroker
                        4
                        12
                        905
                        Loading More Posts
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes
                        Reply
                        • Reply as topic
                        Log in to reply
                        Community
                        Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                        The ioBroker Community 2014-2023
                        logo