How to round numbers to show as $2.4M, $1.2k etc

I am trying to figure out how I can make the numbers look like this? So $2.4M, $1.2K .

I am getting close lol. I think I might need to regex it to pull out the second number.


you can use a series of conditions (or boolean statements formatted as text), something like this..

x < 1,000 : just print the number

x >= 1,000 and < 1,000,000 : divide by 1000 and round to 1 decimal place and append K

x >= 1,000,000 divide by 1,000,000 : round to 1 decimal place and append M

6 Likes

You are the best! Thanks!

Can you imagine if we could use custom events as a data source (rather than action)? It would make stuff like this so much easier.

One thing we can do at the moment is use a property on a global reusable element, which we can drop anywhere. That takes the number and returns the text.

2 Likes

FYI: Javascript’s standard library has an answer to that: Intl.NumberFormat - JavaScript | MDN

I put together a little plugin for myself that does that: 🤌 Number formatter Plugin | Bubble

Demo and editor

3 Likes

That cool!

This topic was automatically closed after 70 days. New replies are no longer allowed.