# Change text into a percentage including a Global Variable?

## How do I…

Hey there! I’m trying to create a map that shows a percentage of how much has been explored. Most of the code is done without any issue, the final problem I’m having is actually converting it to a percentage.

This is what I got going on. The amount of things in the forest area for example, might be 18. 12 of those are maps, 3 are treasures, ect ect. Each time you enter a location the first time, or open the chest the first time, the counter goes up. It’s a global variable, and this part is working just fine.

The problem I’m struggling with, is how to convert the text that the player sees, to a percentage out of 18, based on the number of the global variable.

## Related screenshots

The ‘change text of ForestMapPercentage’ is where I’m struggling. I can easily change it to the Global Variable, but when I try to figure out how to alter it from there, I’m stumped.

I want it to do something like this:

Change the text of ForestMapPercentage: set to GlobalVariableString(Save.FullMaps.ForestMapSecretTotal), then show the percentage of that global variable out of the number 18.

I’m completely stumped on this one. Can anyone help me out? Thank you so much!

The formula is variable*100/18

Thank you! But when I type it in, it becomes red and does not work. How can I make it work?

The ForestMapSecretTotal should be a number but, you can make it work with this:

ToString(ToNumber(GlobalVariableString(Save.FullMaps.ForestMapSecretTotal))*100/18)

Or, simplified, `ToString(GlobalVariable(Save.FullMaps.ForestMapSecretTotal)*100/18)`.

YES thank you this works! I guess my one final issue, is how to round it up to a solid number. Right now I’m getting a ton of decimal numbers. I appreciate this so much you guys!

Okay nevermind! I looked around the forums and found out about the Math Extension, now it works perfectly!

2 Likes

FYI: You don’t need an extension you can use trunc(#) or round(#) or roundTo(#,#)

trunc(#) is short for truncate. It returns just the whole number.
trunc(1.126) would give you 1

round(#) Rounds to the nearest number
round(1.126) would give you 1
round(1.6) would give you 2

roundTo(#,#) Rounds the first number to the 2nd number of places.
roundTo(1.126, 1) would give you 1.1
roundTo(1.126, 2) would give you 1.13

https://wiki.gdevelop.io/gdevelop5/all-features/expressions-reference/#mathematical-tools