将数字转换为指定格式的字符串 [英] Convert number to string in a specified format

查看:80
本文介绍了将数字转换为指定格式的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个像下面这样的函数,它应该有2个输入数字和一个字符串格式



例如





I need a function like below which should have 2 inputs a number and a string format

for example


string ConvertnumbertoString(string sFormat,int number)
{
return convertedstring
}





如果我调用这样的函数ConvertnumbertoString( $$$$$ 281

然后我的输出应 00281



更多样品



&&&& 15 = 0015

&&&&& 15 = 00015

$ 15 = 15




我怎么能这样做...请帮助我



if i call function like this ConvertnumbertoString("$$$$$",281)
then my output should be 00281

some more samples

&&&& 15 = 0015
&&&&& 15 = 00015
$ 15 = 15


How can i do this..please help me

推荐答案

281

然后我的输出应 00281



更多样品



&&&& 15 = 0015
&&&& 15 = 00015
",281)
then my output should be 00281

some more samples

&&&& 15 = 0015
&&&&& 15 = 00015


15 = 15



我该怎么办...请帮助我
15 = 15

How can i do this..please help me


您好,



看看这里:

标准数字格式字符串 [ ^ ]

自定义数字格式字符串 [ ^ ]

如何:使用前导零填充数字 [ ^ ]

Int [C#]的字符串格式 [ ^ ]
Hi,

Have a look here:
Standard Numeric Format Strings[^]
Custom Numeric Format Strings[^]
How to: Pad a Number with Leading Zeros[^]
String Format for Int [C#][^]


这篇关于将数字转换为指定格式的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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