delphi floattostr 保留2位小数
时间: 2023-06-28 21:08:12 浏览: 110
在 Delphi 中,可以使用以下代码将一个浮点数转换为字符串并保留两位小数:
```
var
myFloat: Double;
myStr: string;
begin
myFloat := 3.14159;
myStr := Format('%.2f', [myFloat]);
ShowMessage(myStr);
end;
```
在上面的示例中,`Format` 函数的第一个参数是格式字符串,`%.2f` 表示保留两位小数的浮点数。第二个参数是一个数组,其中包含要格式化的值。在这种情况下,我们只有一个值 `myFloat`。最后,将格式化的字符串赋值给 `myStr` 变量,并在窗口中显示出来。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![text/plain](https://img-home.csdnimg.cn/images/20210720083646.png)
![text/x-c++](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![caj](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)