Showing two decimal place numbers and adding them properly


I am stuck while adding the dollars with two decimal values .The values are not rounded to 2 decimal places and the addition is result just appending the values.It adds the values as strings.

Please note.If there are no decimal values the addition function works fine.

1 Like

If your blocks are not working the way you expect them to, post a screenshot of the blocks you are using.

You should also give an example of two values you’ve tried to add and the sun that Thunkable is displaying.

1 Like

When the button ‘plus 1’ and ‘plus 2.5’ are clicked it shows the sum as 12.50

That’s strange. That does seem like a possible bug.

Can you post a link to your project?

Also, whenever you use a stored variable, you need to give it a value if it is null. Please try adding a When screen is opened block and inside it, if stored variable add = null then set stored variable to 0.

I tried it but it still doesn’t work.

Hello, i have also faced this similar problem few months ago, when i was making a calculator app, my code was very similar to you.
I suggest you to use set stored variable add instead of change variable add block to add 2.50, i think is a bug, when we try to set a variable to a specific decimal place, it automatically ignores the last zeroes
And one more suggestion, when you use this block: set variable add to add + 2.50, it will change your variable and text to 2 decimal places but, then also have to use +1.001 (or any number that can be rounded of to 1.00 like 1.000003, 1.000342) with 2 decimal places, because if you click button b, it will change 5.00 to 6, instead of 6.00
So, i think you got your answer, Try this code

And this issue you say is a javascript bug, the thunkable compiler instead of adding 2.50, it first auto round off 2.50 to 2.5 and then concatenate it with previous sum, see as you click it only adds 2 and 5 to the text and the text becomes longer and longer

Try this :slight_smile:

I would do this:

1 Like

Thank you sir, it works now, I will be implementing this to my app. Thank you so much.

1 Like

I need some help with my canteen app, I can’t show the total on screen two and i don’t know how to integrate the decimal solution. I’ll insert the link to my project, please have a look. Will help me greatly. thank you.

Thanks for sharing the link. Can you also post a screenshot of which blocks you’re using to display the total?

@baladitya.harshavard, it was so easy, you have to just this total with 2 decimal places block

Note: Just remember,to show a number with decimal, you have to use this __ with _ decimal places block
Here is your updated app:

Thank you so much, but i’ve got a new problem. In screen two when you add the items, and when you minus with a random minus button it subtracts the total.

@baladitya.harshavard please explain the issue :face_with_monocle: :face_with_monocle: and send link of new app,
What do you mean by : random minus button and subtracts the total
But the issue i understand, is that you trying to say that if you click on minus btn of any item with 0 items taken, it does not make the item -1 but still cut the price,
And from the screenshot, you are trying to say that you 2 burgers of 10$, but the total is 0$, when you click on minus btn of cola 4 times.
If this is your issue, then the solution is, you have to use conditions, when user click on minus btn, if count is 0, then show a text or alert message intead of calling the sum function and rewriting the total.

If this is not the issue, then please elaborate the problem in more detail and send link.

1 Like

I have fixed the problem myself, thank you for your time.

1 Like

If you have solved your problem, then please mark this issue as solved. :grinning: :grinning: :grinning:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.