Skip to main content
Question

Facing issue while creating a basic calculator using Figma variables


I am trying to create a basic calculator using Figma variables.
The calculator has 1-9 number keys and a result section linked to number variable #Result

Interaction on numbers takes place as follow:

Interaction logic:

Prototype mode: On clicking 7 multiple type result displayed is as follows:
Expected: 0, 7(0x10+7), 77(7x10=7),777, 7777, 77777, 777777,
Unexpected: 77777776, 777777792, -2147483648 (and stops)

Can anyone help me with the reason for this error, as I have rechecked all logics carefully.

3 replies

ksn
Figmate
  • Community Support
  • 1655 replies
  • March 15, 2024

Hey @Shraddha_Poddar – can you send a copy of your calculator prototype over to our support team? I think this would be better addressed by them. They can check the connections to see where things may be breaking.

You can file a ticket here: https://help.figma.com/hc/en-us/requests/new?ticket_form_id=360001744374


Thanks @ksn

I have raised a ticket with the above issue.
Looking forward to hearing soon!


stammeredads
  • New Participant
  • 7 replies
  • April 9, 2025

The unexpected results in your Figma calculator (like 77777776, -2147483648) are likely due to integer overflow. When you keep multiplying the result by 10 and adding digits (e.g., Result * 10 + 7), the number quickly grows beyond the 32-bit integer limit (2,147,483,647), causing it to wrap into negative values. To fix this, treat the result as a string and use string concatenation (e.g., Result + "7") instead of arithmetic. This approach also mimics how real calculators display inputs. If you're building tools like this, you might enjoy designing a CGPA calculator as well—similar logic, but more academic use. Let me know if you'd like help with that too!


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings