简体   繁体   English

如何四舍五入到最接近的小数? 例如 23.33 到最终 output 到 23.5 和 23.55 到最终 output 到 24

[英]How to round up to nearst decimals? E.g. 23.33 to final output to 23.5 and 23.55 to final output to 24

How to round up to nearst decimals?如何四舍五入到最接近的小数? Eg 23.33 to final output to 23.5 and 23.55 to final output to 24例如 23.33 到最终 output 到 23.5 和 23.55 到最终 output 到 24

Use ceil() function to "round up to closest 0.5".使用ceil() function 来“四舍五入到最接近的 0.5”。

ceil(col * 2) / 2

The above will return -1 for -1.3.上面将返回 -1 为 -1.3。 If you instead want -1.5, do如果您想要-1.5,请执行

sign(col) * CEIL(ABS(col) * 2) / 2

https://dbfiddle.uk/L3bKT-V7 https://dbfiddle.uk/L3bKT-V7

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何设置一个输出参数,它是两个字段的组合,例如fullname = firstname + lastname? - How to set an output parameter that is the combination of two fields, e.g., fullname=firstname+lastname? 如何避免在 SELECT 语句中用于排序的额外列到最终输出? - How to avoid the extra column used for ordering in the SELECT statement to the final output? 两个逗号分隔的单元格与最终输出合并 - Two comma seperated cell merge with final output 在最终存储过程SELECT / OUTPUT中对列重新排序 - Reorder columns in final stored procedure SELECT / OUTPUT Sql查询加入两个表进行最终输出 - Sql query to join two table for the final output SQL Server - 如何向上或向下舍入小数? - SQL Server - How to round up or down decimals? SQL如何四舍五入到十分之一(没有小数) - SQL how to round up to tenth (no decimals) 时间字段,例如“14:24:05” - 仅显示“14:24”而不显示秒 - Time field e.g. "14:24:05" - show only "14:24" without seconds 我如何将两列合并为一列(最终输出)(python / sqlite) - How can i merge two columns into one (final output) (python/sqlite) 我想在最终的 output 表中显示来自 dbo.orders 的总金额。如何? - i want to display total_amount from dbo.orders in final output table .how?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM