切り上げ,切り捨て,四捨五入

[具体的な関数]

[使用例]

  1. ceil,floor,round,trunc の使用方法です.
    #include <iostream>
    #include <cmath>
    
    using namespace std;
    
    int main()
    {
    	double vp1 = 3.14, vp2 = 3.77, vm1 = -3.14, vm2 = -3.77;
    	cout << "vp1 : " << vp1 << ", vp2 : " << vp2 << ", vm1 : " << vm1 << ", vm2 : " << vm2 << endl;
    	cout << "  ceil(vp1) " << ceil(vp1) << "  ceil(vp2) " << ceil(vp2) << " ceil(vm1) " << ceil(vm1) << " ceil(vm2) " << ceil(vm2) << endl;
    	cout << "  floor(vp1) " << floor(vp1) << "  floor(vp2) " << floor(vp2) << " floor(vm1) " << floor(vm1) << " floor(vm2) " << floor(vm2) << endl;
    	cout << "  round(vp1) " << round(vp1) << "  round(vp2) " << round(vp2) << " round(vm1) " << round(vm1) << " round(vm2) " << round(vm2) << endl;
    	cout << "  trunc(vp1) " << trunc(vp1) << "  trunc(vp2) " << trunc(vp2) << " trunc(vm1) " << trunc(vm1) << " trunc(vm2) " << trunc(vm2) << endl;
    
    	return 0;
    }
    			
    (出力)
    vp1 : 3.14, vp2 : 3.77, vm1 : -3.14, vm2 : -3.77
      ceil(vp1) 4  ceil(vp2) 4 ceil(vm1) -3 ceil(vm2) -3
      floor(vp1) 3  floor(vp2) 3 floor(vm1) -4 floor(vm2) -4
      round(vp1) 3  round(vp2) 4 round(vm1) -3 round(vm2) -4
      trunc(vp1) 3  trunc(vp2) 3 trunc(vm1) -3 trunc(vm2) -3			

菅沼ホーム 本文目次 演習問題解答例 付録目次 索引