the integer part of the division (2024)

the integer part of the division (1)

Walter Roberson on 5 Oct 2012

Consider -23/5 (that is, the case of negative numbers.) Should that be -4 times 5 and remainder -3, or should it be -5 times 5 and remainder 2 ?

If you want the -4 version so that abs() of the "integer part" of -23/5 and 23/5 are the same, then use fix()

If you want the -5 version so that the remainder is always non-negative, then use floor()

You can use either fix() or floor() if you only have positive values, with floor() being preferred (more efficient, mathematically clearer)

Do not use round() even if you have only positive values. round(23/5) is 5, not 4.

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

the integer part of the division (2024)
Top Articles
Latest Posts
Article information

Author: Francesca Jacobs Ret

Last Updated:

Views: 5909

Rating: 4.8 / 5 (68 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Francesca Jacobs Ret

Birthday: 1996-12-09

Address: Apt. 141 1406 Mitch Summit, New Teganshire, UT 82655-0699

Phone: +2296092334654

Job: Technology Architect

Hobby: Snowboarding, Scouting, Foreign language learning, Dowsing, Baton twirling, Sculpting, Cabaret

Introduction: My name is Francesca Jacobs Ret, I am a innocent, super, beautiful, charming, lucky, gentle, clever person who loves writing and wants to share my knowledge and understanding with you.