Figma Support Forum

Floating point problem with Plugin API

I create PaintStyles and TextStyles via Plugin API. Sometimes I set decimal values like r,g,b,a or letterSpacing.

Later on, I want to control those values that I created with API in order to avoid duplicate styles. However, getLocalTextStyles and getLocalPaintStyles return me back my decimal values with very high precision.

For example I set: 0.11 and get back 0.10999999940395355. So, this makes my comparison very complicated and even impossible sometimes.

Am I missing something or is it an issue?

Thanks for your help.

Hey Hakan!
You can probably get around this by using .toFixed(2) on all those numbers.

Thanks Finch. I was using Math.round after multiplication, but toFixed makes more sense. I wanted be sure if I was using wrongly the API but I think that it is the expected behavior. Thanks again.