round 函数
round 函数
要求四舍五入的情况,用round函数就很方便。
一、用法
1.基本用法
对于小数而言,round()函数仅仅保留到整数位,仅对小数点后一位进行四舍五入。
比如:round(1.5) = 2.000000,round(1.57) = 2.000000
2.保留小数用法
如果想要保留小数位数可以先乘后除以达到效果
举个栗子:
1 |
|
二、手写版本
1 | double round(double x) |
三、例题
[abc273_b](B - Broken Rounding (atcoder.jp) )
题意:给你一个非负整数
操作:对数字
比如:
思路:先变成小数,对其进行保留到整数位的四舍五入,在乘回来。
1 |
|
- Title: round 函数
- Author: Nannan
- Created at : 2023-07-09 12:36:00
- Updated at : 2024-09-30 21:06:37
- Link: https://redefine.ohevan.com/2023/07/09/round/
- License: This work is licensed under CC BY-NC-SA 4.0.
Comments