# how do i put a number variable to show 1000 as 1K, 1000000 as 1M, etc... Attention Topic was automatically imported from the old Question2Answer platform. Asked By tonykkjk

I’m making a game with a “price” variable, and every time you buy a upgrade, the price goes * 1.5, but the price that it costs is different then the price that shows at the button, because i set to every time the price variable hits more than “999”, it turns to 1, but at this case, the price is 1.5, and the price showing at the button is just “1k”, and when it gets doubled, the button price get as “2k” and the real price as “3000”.

How do i fix this?

supply sample code and variable declarations.

wyattb | 2021-06-05 22:40

``````var preco = 100
var level = 0
var valor = ""

signal comprou

func _process(_delta):
if preco >= 999 and valor == "":
valor = "K"
preco = 1
elif preco >= 999 and valor == "K":
valor = "M"
preco = 1
elif preco >= 999 and valor == "M":
valor = "B"
preco = 1
elif preco >= 999 and valor == "B":
valor = "T"
preco = 1
elif preco >= 999 and valor == "T":
valor = "Q"
preco = 1
elif preco >= 999 and valor == "Q":
valor = "QQ"
preco = 1
elif preco >= 999 and valor == "QQ":
valor = "S"
preco = 1
elif preco >= 999 and valor == "S":
valor = "SS"
preco = 1
elif preco >= 999 and valor == "SS":
valor = "OC"
preco = 1
elif preco >= 999 and valor == "OC":
valor = "N"
preco = 1

\$Preco.text = "%d" % [floor(preco)] + (valor)
\$Level.text = String(level)

preco = preco * 1.5
level = level + 1
emit_signal("comprou")
``````

“preco” = price
“valor” = value

tonykkjk | 2021-06-06 01:17 Reply From: nahcode

i dont know how node hierarchy on your project so i just make it more easier for me,
you can try this

``````extends Node2D

var preco = 100
var level = 0
var valor = ""

func _process(_delta):
if preco >= 999 and valor == "":
valor = "K"
preco = 1
elif preco >= 999 and valor == "K":
valor = "M"
preco = 1
elif preco >= 999 and valor == "M":
valor = "B"
preco = 1
elif preco >= 999 and valor == "B":
valor = "T"
preco = 1
elif preco >= 999 and valor == "T":
valor = "Q"
preco = 1
elif preco >= 999 and valor == "Q":
valor = "QQ"
preco = 1
elif preco >= 999 and valor == "QQ":
valor = "S"
preco = 1
elif preco >= 999 and valor == "S":
valor = "SS"
preco = 1
elif preco >= 999 and valor == "SS":
valor = "OC"
preco = 1
elif preco >= 999 and valor == "OC":
valor = "N"
preco = 1

\$Preco.text = str(stepify(preco, 0.1), valor)
\$Level.text = String(level)
print(preco)

func _input(event):
if event.is_action_pressed("ui_up"):
level_up()

func level_up():
preco = preco * 1.5
level = level + 1
``````

im using the button to call the level_up price instead of calling a signal, because im not using manual signal alot, but i think you can implement this too on your project

It worked, but the price that shows at the button is different than the real price that it costs, ill try to fix it myself

tonykkjk | 2021-06-06 11:10 Reply From: wyattb

Ok a better way is to just use an array having the limits and scale format. Also do not call _ready() as a function. Normally they are called by events.

E.g.

``````extends Button

var preco = 100
var level = 0
var valor
var scale

signal comprou

func _process(_delta):
pass

scale=0
valor = [[1,"%10.0f"],[1000.0,"%10.2fK"],[1e6,"%10.2fM"],[1e9,"%10.2fB"],[1e12,"%10.2fT"]]
format()
pass

func format():
var  prcf
# check if price reached next scale
if preco>=valor[scale+1]:
prcf=preco/valor[scale+1]
scale+=1
else:
prcf=preco/valor[scale]

text =  valor[scale] % [prcf]