round,floor,ceil,trunc

直接贴上C Plus Plus的代码,很容易懂

/* round vs floor vs ceil vs trunc */
#include <stdio.h>      /* printf */
#include <math.h>       /* round, floor, ceil, trunc */

int main ()
{
	const char * format = "%.1f \t%.1f \t%.1f \t%.1f \t%.1f\n";
	printf ("value\tround\tfloor\tceil\ttrunc\n");
	printf ("-----\t-----\t-----\t----\t-----\n");
	printf (format, 2.3,round( 2.3),floor( 2.3),ceil( 2.3),trunc( 2.3));
	printf (format, 3.8,round( 3.8),floor( 3.8),ceil( 3.8),trunc( 3.8));
	printf (format, 5.5,round( 5.5),floor( 5.5),ceil( 5.5),trunc( 5.5));
	printf (format,-2.3,round(-2.3),floor(-2.3),ceil(-2.3),trunc(-2.3));
	printf (format,-3.8,round(-3.8),floor(-3.8),ceil(-3.8),trunc(-3.8));
	printf (format,-5.5,round(-5.5),floor(-5.5),ceil(-5.5),trunc(-5.5));
	return 0;
}


/*
Output:

value   round   floor   ceil    trunc
-----   -----   -----   ----    -----
2.3     2.0     2.0     3.0     2.0
3.8     4.0     3.0     4.0     3.0
5.5     6.0     5.0     6.0     5.0
-2.3    -2.0    -3.0    -2.0    -2.0
-3.8    -4.0    -4.0    -3.0    -3.0
-5.5    -6.0    -6.0    -5.0    -5.0

*/

round是四舍五入

floor是向下取值

ceil是向上取值

trunc是正数向下,负数向上

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,"FUNCTION mysql.TRUNC does not exist" 是一句错误的语法,因为在MySQL中并不存在名为mysql.TRUNC的函数。 MySQL中存在的取整函数有CEIL(x)和FLOOR(x),用于向上取整和向下取整,而TRUNC(x)函数并不存在。如果需要进行向0取整操作,可以使用ROUND(x, 0)函数。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [ora_trunc_table.sh](https://download.csdn.net/download/qq_44901599/12095300)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [python 基础 python math库的使用,展示了math库中常用的函数并给出python2的示例](https://download.csdn.net/download/li171049/88225507)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [MySQL 5.7启动数据库报错'does not exist or is not executable'](https://blog.csdn.net/cuantangnie3915/article/details/100491267)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值