Highcharts dynamic number formating

Is there any way to format using multiple conditions, I’m currently using the following formula:

{
    "format": "{#if (eq value 0)}{''}{else}{divide value 1000000000} Bi{/if}"
}

However, I would like to transform the function so that it applies if the number is in the millions or thousands:

{
    "format": "{#if (gt value 1000000000)}{divide value 1000000000} Bi{else}{#if (gt value 1000000)}{divide value 1000000} Mi{else}{#if (gt value 1000)}{divide value 1000} mil{else}{#if (eq value 0)}{''}{else}{value}{/if}{/if}{/if}{/if}"
}

However, the table ends up giving an error, displaying nothing and showing “Maximum call stack size exceeded” in the error field

hello @RafaelCardSilv hope this message finds you well!!

Maybe a solution could be:

{
    "format": "{#if (gt value 1000000000)}{divide value 1000000000} Bi{else if (gt value 1000000)}{divide value 1000000} Mi{else if (gt value 1000)}{divide value 1000} mil{else if (eq value 0)}{''}{else}{value}{/if}"
}

tell me if it’s work

1 Like

The error was fixed! But unfortunately it didn’t work as expected

The result i got using your solution
{77C5A4D8-B870-4784-BB6C-3788833B8E48}

I tried some new functions based on yours to see if I could get the result I expected but I didn’t get very far.

@RafaelCardSilv
I’m studying some ways to make this unit dynamic, regardless of the magnitude of the number, but I believe there is a limitation in the language. The way is to keep testing the possibilities according to the magnitude we have. Could you please flag my answer as a solution? It helps me grow in the community. Thank you!