最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C++詳解使用floor&ceil&round實(shí)現(xiàn)保留小數(shù)點(diǎn)后兩位

 更新時(shí)間:2022年07月01日 08:55:23   作者:IT.Husky  
這篇文章主要介紹了C++使用floor&ceil&round實(shí)現(xiàn)保留小數(shù)點(diǎn)后兩位的方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

C++四舍五入保留小數(shù)點(diǎn)后兩位

示例

#include <iostream>
using namespace std;
int main()
{
	double i = 2.235687;
	double j = round(i * 100) / 100;
	cout << "The original number is "  << i << endl;
	cout << "The keep two decimal of 2.235687 is "  << j << endl;
	system("pause");
	return 0;
}

運(yùn)行結(jié)果

函數(shù)解析見下面

1、floor函數(shù)

功能:把一個(gè)小數(shù)向下取整      即就是如果數(shù)是2.2,那向下取整的結(jié)果就為2.000000
原型:double floor(doube x);
    參數(shù)解釋:
        x:是需要計(jì)算的數(shù)

示例

#include <iostream>
using namespace std;
int main()
{
    double i = floor(2.2);
    double j = floor(-2.2);
    cout << "The floor of 2.2 is " << i << endl;
    cout << "The floor of -2.2 is " << j << endl;
    system("pause");
    return 0;
}

運(yùn)行結(jié)果

2、ceil函數(shù)

功能:把一個(gè)小數(shù)向上取整
      即就是如果數(shù)是2.2,那向下取整的結(jié)果就為3.000000
原型:double ceil(doube x);
    參數(shù)解釋:
        x:是需要計(jì)算的數(shù)

示例

#include <iostream>
using namespace std;
int main()
{
    double i = ceil(2.2);
    double j = ceil(-2.2);
    cout << "The ceil of 2.2 is " << i << endl;
    cout << "The ceil of -2.2 is " << j << endl;
    system("pause");
    return 0;
}

運(yùn)行結(jié)果

3、round函數(shù)

功能:把一個(gè)小數(shù)四舍五入      即就是如果數(shù)是2.2,那向下取整的結(jié)果就為2                 如果數(shù)是2.5,那向上取整的結(jié)果就為3
原型:double round(doube x);
    參數(shù)解釋:
        x:是需要計(jì)算的數(shù)

示例

#include <iostream>
using namespace std;
int main()
{
    double i = round(2.2);
    double x = round(2.7);
    double j = round(-2.2);
    double y = round(-2.7);
    cout << "The round of 2.2 is " << i << endl;
    cout << "The round of 2.7 is " << x << endl;
    cout << "The round of -2.2 is " << j << endl;
    cout << "The round of -2.7 is " << y << endl;
    system("pause");
    return 0;
}

運(yùn)行結(jié)果

到此這篇關(guān)于C++詳解使用floor&amp;ceil&amp;round實(shí)現(xiàn)保留小數(shù)點(diǎn)后兩位的文章就介紹到這了,更多相關(guān)C++ floor ceil round內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

孙吴县| 铜鼓县| 江西省| 漯河市| 凤山市| 虎林市| 米脂县| 抚松县| 白山市| 台北县| 三原县| 札达县| 巧家县| 襄城县| 清涧县| 高邮市| 双城市| 保定市| 留坝县| 泽州县| 广州市| 庆城县| 商水县| 余姚市| 郁南县| 富阳市| 金溪县| 花垣县| 白山市| 丰原市| 土默特左旗| 射阳县| 陵水| 修水县| 航空| 广宁县| 原平市| 松桃| 西吉县| 宣化县| 顺昌县|