Algorithm: integer division on rounding

Source: Internet
Author: User

Writing the code encounters an integer division that needs to be rounded up.

1. Integer division, you can write your own ^_^

1#!/bin/Bash2 3num=101# #被除数4Pre=Ten# #除数5 6 # #线上取整7res=$[(num+pre-1)/Pre]8 Echo$res9 Ten # # integer division By default is rounded down  Oneres=$[num/Pre] A Echo$res

2. Or you can provide a method based on the language used

For example, the C + + MATH.H header file provides built-in methods:

1 round   2  Floor 3 Ceil

Algorithm: integer division on rounding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.