I am new to Bubble and currently checking out Bubble to build a real estate app. I am having problem trying to shorten large currency number e.g. $500,000 or $1,000,000 to $500K and $1M respectively for google map markers.
Thanks @manikandan for your response and solution and as this is my first time trying to use a script in Bubble, hope you do not mind explaining how to attach and run the script dynamically to update google map markers with shorter currency form upon page load.
I did use the Toolbox plugin for the script but not sure how to attach it to the marker to display the short form dynamically. Do I use the script when user inputs the currency field and store it into the database before displaying the short form on the google map markers?
thanks again for your help!
Hi,
Let me suggest another javascript way to achieve the same result
(function(x) {
if(x < 9999) {
return x;
}
if(x < 1000000) {
return Math.round(x/1000) + "K";
}
if( x < 10000000) {
return (x/1000000).toFixed(2) + "M";
}
if(x < 1000000000) {
return Math.round((x/1000000)) + "M";
}
if(x < 1000000000000) {
return Math.round((x/1000000000)) + "B";
}//and so on...
return "the number is too big;})
Defining a function between parenthesis allow you to call it in place, without even giving it a name.
That allows you to pass a single value to it (the number you wish to format) and retrieve the result of the function using the “Expression” element from the toolbox plugin using this syntax : (function(x) {if... ...})(Your_Number);
just as in this example :
thanks Stern for the advice and it works great!
It really helps me greatly and now i have a better understanding of using javascript script in Bubble. Just wish that there are more info like this in Bubble documentation / manual.
Thanks Nigel and this works great too!
Appreciate your tips to achieve the same results without using any script !
As i learn more about Bubble, it seems like a powerful and sophisticated no-code development platform but it lacks good in-depth user guide for non-developers and newbies and learning Bubble is a “trial and error” with lots of “hit & miss”. just my 2 cents!
Thanks @stern.solal@NigelG for the tips. You guys are what makes this community better. Without such tips and suggestions, newbies like me will never take off, given the lack of organized documentation in Bubble.
Not only this solves the problem but i am seeing considerable speed in showing data this way. The older way of showing whole number is taking more time to load than this…