ceil

Get ceiling integer from number in linux (BASH)

房东的猫 提交于 2019-11-26 22:16:23
问题 How would I do something like: ceiling(N/500) N representing a number. But in a linux Bash script 回答1: Call out to a scripting language with a ceil function. Given $NUMBER : python -c "from math import ceil; print ceil($NUMBER/500.0)" or perl -w -e "use POSIX; print ceil($NUMBER/500.0), qq{\n}" 回答2: Why use external script languages? You get floor by default. To get ceil, do $ divide=8; by=3; let result=($divide+$by-1)/$by; echo $result 3 $ divide=9; by=3; let result=($divide+$by-1)/$by; echo

How to ceil, floor and round bcmath numbers?

六眼飞鱼酱① 提交于 2019-11-26 16:41:46
问题 I need to mimic the exact functionality of the ceil(), floor() and round() functions on bcmath numbers , I've already found a very similar question but unfortunately the answer provided isn't good enough for me since it lacks support for negative numbers and the precision argument for the round() function is missing . I was wondering if anyone can come up with a rather short and elegant solution to this problem. All input is appreciated, thanks! 回答1: After a night lost trying to solve this

Rounding up and down a number C++

折月煮酒 提交于 2019-11-26 11:37:40
问题 I\'m trying to allow my program to round a number up and down respectively. For example, if the number is 3.6 , my program is suppose to round up the nearest number which is 4 and if the number is 3.4 , it will be rounded down to 3. I tried using the ceil library to get the average of 3 items. results = ceil((marks1 + marks2 + marks3)/3) However, the ceil only rounds the number down but does not roll the number up. There\'s 1 algorithm i stumbled upon var roundedVal = Math.round(origVal*20)

Java Number & Math 类

怎甘沉沦 提交于 2019-11-26 00:31:07
一般地,当需要使用数字的时候,我们通常使用内置数据类型,如: byte、int、long、double 等。 int a = 5000; float b = 13.65f; byte c = 0x4a 然而,在实际开发过程中,我们经常会遇到需要使用对象,而不是内置数据类型的情形。为了解决这个问题,Java 语言为每一个内置数据类型提供了对应的包装类。 所有的包装类 (Integer、Long、Byte、Double、Float、Short) 都是抽象类 Number 的子类。 这种由编译器特别支持的包装称为装箱,所以当内置数据类型被当作对象使用的时候,编译器会把内置类型装箱为包装类。相似的,编译器也可以把一个对象拆箱为内置类型。Number 类属于 java.lang 包。 下面是一个使用 Integer 对象的实例: Test.java 文件代码 public class Test{ public static void main(String args[]){ Integer x = 5; x = x + 10; System.out.println(x); } } 以上实例编译运行结果如下: 15 当 x 被赋为整型值时,由于x是一个对象,所以编译器要对x进行装箱。然后,为了使x能进行加运算,所以要对x进行拆箱。 Java Math 类 Java 的 Math