Scirra / Construct-feature-requests

A place to submit feature requests and suggestions for Construct.
https://www.construct.net
11 stars 1 forks source link

Extend zeropad() functionality #381

Open oosyrag opened 1 month ago

oosyrag commented 1 month ago

Reviewed guidelines

Checked for duplicate suggestions

Summary

Allow zeropad to add trailing zeros. One common example would be currencies with cents ($1.00).

Possible workarounds or alternatives

Separate out the decimal portion and integer portion. Use zeropad() to add zeros for the decimal portion.

For number "n", with "d" trailing zeros - set text to int(n) & "." & zeropad(round((n-int(n))*10^d),d)

(Although this doesn't work quite right with negative numbers, hence #380 where int() could be replaced with trunc(), or the expanded conditional expression.)

Proposed solution

Allow zeropad to access negative numbers for "d" where a negative value indicates how many digits worth of trailing zeros are to be added.

Alternatively a separate expression could be added for trailing zeroes as zerotrail(n,d), as opposed to zeropad() for leading zeroes.

Why is this idea important?

QoL expression for displaying currencies, or floats with a fixed amount of digits for spacing purposes.

It can be atheistically important (especially with quickly changing numbers involving decimals), so that the alignment is not thrown off when the number of digits displayed changes due to non significant trailing zeroes.

Additional remarks

Thanks!

F3der1co commented 1 month ago

The built-in internationalization plugin has formatting for currencies and decimals, so at least for that case there already is a good solution.

oosyrag commented 1 month ago

The built-in internationalization plugin has formatting for currencies and decimals, so at least for that case there already is a good solution.

I missed that, thanks!