显示浮动为String至少有1位小数 [英] Display Float as String with at Least 1 Decimal Place

查看:183
本文介绍了显示浮动为String至少有1位小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要显示一个浮动作为一个字符串,同时确保至少显示一位小数。如果有更多的小数,我想这显示。

I want to display a float as a string while making sure to display at least one decimal place. If there are more decimals I would like those displayed.

例如:
1应显示为1.0
1.2345应显示为1.2345

For example: 1 should be displayed as 1.0 1.2345 should display as 1.2345

有人可以帮助我的格式字符串?

Can someone help me with the format string?

推荐答案

使用的ToString(0 ###########),尽可能多的#作为小数你想要的。

Use ToString(".0###########") with as much # as decimals you want.

这篇关于显示浮动为String至少有1位小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆