isprojects / mstform

Mobx State Tree Form-library
MIT License
81 stars 3 forks source link

Add a new property to display a flexible minimum amount of decimals. … #141

Closed kdleijer closed 4 years ago

kdleijer commented 4 years ago

Add a new property to display a flexible minimum amount of decimals. Show more if we have more.

Added this new property for a customer that is wishing to display prices in at least 2 and at most 10 decimals. But, if, for instance, a price does not have more than 3 decimals, we do not want to show all trailing zeros

RickLucassen commented 4 years ago

I see you've changed the behavior of the parseDecimal function. This function, together with normalizedDecimalPlaces is used to change the input to a format the backend would accept. This doesn't change the way the decimal is presented visually.

So to accomplish what you want you would need to change the renderDecimal function. Together with decimalPlaces this handles how much decimals will be shown and how many zeroes need to be added. Since we already would receive these decimals from the backend with enough decimals in place I would suggest adding a "removeZeroes" boolean (and functionality) and in the application set the decimalPlaces to the maximum amount of decimals.

This however doesn't catch the case of "minimum amount of decimals".

kdleijer commented 4 years ago

DIscussed to not implement it like this, but to rewrite it