bcb中有四舍五入的函数吗

qlsoftzj 2003-11-05 02:07:40
bcb中有四舍五入的函数吗?
...全文
238 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
yjy1001 2003-11-05
  • 打赏
  • 举报
回复
RoundTo() ;//四舍 5入

TrunC();//向下取整

具体 使用 请查看帮助 都有例子的
Behard 2003-11-05
  • 打赏
  • 举报
回复
float fTemp = 1.4;
int iTemp = fTemp+ 0.5;
ShowMessage ( IntToStr(iTemp) );

fTemp = 1.6;
iTemp = fTemp+ 0.5;
ShowMessage ( IntToStr(iTemp) );
GeoPhoenix 2003-11-05
  • 打赏
  • 举报
回复
float b = 0.6;
int a = (int) (b+0.5);
Atomictry 2003-11-05
  • 打赏
  • 举报
回复
哈哈,给参数加上0.5,你就知道怎么搞了。
borland_boy 2003-11-05
  • 打赏
  • 举报
回复
n=RoundTo(a, b)

//a 要转换的变量
//b 取几位小数注意是负数
我不懂电脑 2003-11-05
  • 打赏
  • 举报
回复
Rounds a floating-point value to a specified digit or power of ten using “Banker’s rounding”.

Unit

Math

Category

Arithmetic routines

typedef Word TRoundToRange;
extern PACKAGE double __fastcall RoundTo(const double AValue, const TRoundToRange ADigit);

Description

Call RoundTo to round AValue to a specified power of ten.

AValue is the value to round.

ADigit indicates the power of ten to which you want AValue rounded. It can be any value from –37 to 37 (inclusive).

RoundTo uses “Banker’s Rounding” to determine how to round values that are exactly midway between the two values that have the desired number of significant digits. This method rounds to an even number in the case that AValue is not nearer to either value.

The following examples illustrate the use of RoundTo:

Expression Value

RoundTo(1234567, 3) 1234000
RoundTo(1.234, -2) 1.23
RoundTo(1.235, -2) 1.24
RoundTo(1.245, -2) 1.24

Note: The behavior of RoundTo can be affected by the Set8087CW procedure or SetRoundMode function.
7rainbow 2003-11-05
  • 打赏
  • 举报
回复
include <Math.hpp>

double n=1.234;

n=RoundTo(n, -2)//取小位后二位 1.23
n=RoundTo(n, -1)//取小位后一位 1.2
ljianq 2003-11-05
  • 打赏
  • 举报
回复
RoundTo();

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧