Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New expression truncate() #380

Open
2 tasks done
oosyrag opened this issue Oct 2, 2024 · 1 comment
Open
2 tasks done

New expression truncate() #380

oosyrag opened this issue Oct 2, 2024 · 1 comment

Comments

@oosyrag
Copy link

oosyrag commented Oct 2, 2024

Reviewed guidelines

  • I have read and understand the suggestion guidelines

Checked for duplicate suggestions

  • I checked for existing similar suggestions

Summary

Construct currently lacks an expression to round towards zero, which can be useful when dealing with negative numbers. Floor() and ceil() round towards negative and positive infinity. Int() sometimes serves this purpose in other programming languages, but behaves as floor() in construct when used on numbers.

Possible workarounds or alternatives

Flooring the absolute value of a number along with a conditional expression that could be used to identify if the number was originally negative to multiply the result by -1.

n<0?abs(floor(n))*-1:floor(n)

Edit: Or using JavaScript math.trunc() as described in the comments below

Proposed solution

A system expression trunc(n) or truncate(n) would remove the decimals or convert a float to an int, rounding towards 0 regardless of n being positive or negative.

Why is this idea important?

This expression would make rounding towards 0 more accessible and easier to implement for a beginner or otherwise not familiar with programming.

Additional remarks

Appreciate your consideration and thanks for all the work you put into Construct, as always.

@F3der1co
Copy link

F3der1co commented Oct 2, 2024

Not to undermine the suggestion, just to give an option here is a workaround by doing it in js with a return function
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants