I’m creating an application where I need to change the values displayed on a label, in currency format, for example: R$ 0.00 to 5.00, 5,000.00 towards as the user clicks on the cards that show the values to be displayed.
In this second format, pressing keys 2 and 3 leaves the label with the format R$ 0.002, R$ 0.003 or R$ 0.000, without deleting a character, so that it leaves it in the format R$ 0.02 or R$ 0.03.
This variable stores the numeric input as a string of digits (like "235" for R$ 2,35).
DIGIT BUTTON LOGIC
For each digit button (Button1, Button2, …, Button9, Button0):
when ButtonX.Click
do
set global RawInput to join global RawInput (ButtonX.Text)
call UpdateLabel
DELETE BUTTON
when ButtonDelete.Click
do
if length of global RawInput > 0 then
set global RawInput to segment global RawInput from 1 to (length of global RawInput - 1)
call UpdateLabel
UPDATE LABEL PROCEDURE
Create a procedure UpdateLabel:
procedure UpdateLabel
do
if length of global RawInput = 0 then
set LabelTotal.Text to "R$ 0,00"
else
// Ensure at least 3 characters for centavos
set paddedInput to join "000" global RawInput
set paddedInput to segment paddedInput from (length of paddedInput - 2) to length of paddedInput
set reaisPart to segment paddedInput from 1 to (length of paddedInput - 2)
set centavosPart to segment paddedInput from (length of paddedInput - 1) to length of paddedInput
// Add thousands separator (optional, for large values)
set reaisWithSeparator to call FormatWithThousandSeparator(reaisPart)
set LabelTotal.Text to join "R$ " join reaisPart "," centavosPart
THOUSAND SEPARATOR PROCEDURE (Optional)
If you want to add dots for thousands (5.000,00), build a helper block FormatWithThousandSeparator(text) to insert . accordingly.
Or start without it and keep the formatting simple.
These are the blocks you showed me, but I also don’t know where to put the component that will do the formatting to make the separator worse by “.”, if you can help me, I appreciate it.