MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    MMM-Cryptocurrency

    Scheduled Pinned Locked Moved Troubleshooting
    9 Posts 3 Posters 1.5k Views 3 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.
    • S Offline
      sdetweil @Tippon
      last edited by

      @tippon has nothing to do w javascript

      how do u get from the text value to the proper number?

      write the steps down

      Sam

      How to add modules

      learning how to use browser developers window for css changes

      S 1 Reply Last reply Reply Quote 1
      • S Offline
        sdetweil @sdetweil
        last edited by sdetweil

        @Tippon get rid of leading non decimal
        remove thousands separator
        if it contains the decimal separator, use string.parseFloat,
        otherwise use string.parseInt
        once u have the right numbers it should work

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        TipponT 1 Reply Last reply Reply Quote 1
        • TipponT Offline
          Tippon @sdetweil
          last edited by

          @sdetweil said in MMM-Cryptocurrency:

          @tippon has nothing to do w javascript

          how do u get from the text value to the proper number?

          write the steps down

          I’m not sure. I know it’s multiplying my number of coins from the wallet section in config.js by the price result from the API, and it’s rounding the figures to the number of decimal points I specified, but I’m getting lost.

          I think I’ve spotted the problem now though, and it seems to be working. These two lines:

          var myPrice=currentCurrency.price.replace("£","");
          var myPrice=myPrice.replace(".", "").replace(",", ".");
          

          strip out the pound sign, then the decimal point, then change the thousands separator to a decimal point.

          Removing the pound sign is at least part of what changes the amount from text to a number (sorry, I’m figuring it out as I’m typing), but removing the decimal point for the low value coins under £1 multiplies their value by 10. e.g. Doge goes from 0.039 to 0039, or 39p. Swapping the thousands separator to a decimal point does the opposite for the large value coins, turning Bitcoin’s £43,000 into £43.000, or £43. I’ve changed it to this:

          var myPrice=currentCurrency.price.replace("£","");
          var myPrice=myPrice.replace(",", "");	
          

          Now the pound symbol is still removed, so the coin’s value is still changed from text to a number, and the thousands separator is removed for the same reason, but without changing the value. I think that the original contributor was European, so uses dots instead of commas for number separation, and changing to GBP messed that up.

          @sdetweil said in MMM-Cryptocurrency:

          @sdetweil get rid of leading no decimal
          remove thousands separator
          if it contains the decimal separator, use string.parseFloat, otherwise use string.parseInt
          once u have the right numbers it should work

          Now that my brain’s caught up with what you were saying, I think I’ve got it right. I have no idea how to use string.parseFloat or string.parseInt though, and no idea how to check which numbers the API sends. That can be my project for tomorrow though, it’s 2am here, and my brain is melting :beaming_face_with_smiling_eyes:

          Thank you for helping me, and giving me a shove in the right direction :thumbs_up: :slightly_smiling_face:

          Please forgive me if I'm slow to reply, I'm currently experiencing memory issues, and sometimes forget that I've asked a question >.<

          S 1 Reply Last reply Reply Quote 0
          • S Offline
            sdetweil @Tippon
            last edited by

            @tippon ok, string.parseInt u have a string (the text variable holds a string value)

            so, you call parseInt() on it and it returns the number for computation
            same for parseFloat (these have decimals)…

            google parseInt and ParseFloat…

            but if u have it working…

            Sam

            How to add modules

            learning how to use browser developers window for css changes

            TipponT 1 Reply Last reply Reply Quote 1
            • TipponT Offline
              Tippon @sdetweil
              last edited by

              @sdetweil parseInt and parseFloat sound vaguely familiar. I was teaching myself Python last year, but had to stop when the schools closed and my daughter was home all day.

              Now that the schools are back, I’m hoping to start again. After trying out MagicMirror, I might learn Javascript first though. I find it a lot easier if I’ve got a real world project to learn about, and MM is more interesting too :)

              Thanks again for your help :)

              Please forgive me if I'm slow to reply, I'm currently experiencing memory issues, and sometimes forget that I've asked a question >.<

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Enjoying MagicMirror? Please consider a donation!
              MagicMirror created by Michael Teeuw.
              Forum managed by Sam, technical setup by Karsten.
              This forum is using NodeBB as its core | Contributors
              Contact | Privacy Policy