[英]C# format float to show 2 places before and after decimal point
I have a time board and want to show time as 01:24 for example.我有一个时间板,例如想将时间显示为 01:24。 My current code:
我当前的代码:
timeInGame.ToString("F2").Replace(".",":");
This code returns 1:24.此代码返回 1:24。
Specify the format explicitly:明确指定格式:
timeInGame.ToString("00.00").Replace(".",":");
Note however that it is incorrect to pretend that decimal numbers map to minutes:seconds or hours:minutes, eg 1.5 == 1:30.但是请注意,将十进制数字 map 假装为分钟:秒或小时:分钟是不正确的,例如 1.5 == 1:30。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.