如何使用字符串值添加.00。小数点最多两个 [英] how to add .00 with a string value. Decimal point upto two

查看:71
本文介绍了如何使用字符串值添加.00。小数点最多两个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨其他人,



需要你的帮助..我有一个文本框,想要在下面的标签上转换它的字符串值。



string.00



例如,texbox中的值为125而不是lable它应该是十进制值125.00







请帮忙。

解决方案

尝试:

 myLabel.Text = myTextBox.Text +  。00; 







但我想用.ToDecimal()方法做到这一点...你能帮助我吗?





听起来像是家庭作业! :笑:



所以,没有代码......但这并不困难。

你需要做的第一件事do是将文本框中的字符串值转换为十进制值。这很简单:使用 decimal.Parse [ ^ ]或 decimal.TryParse [ ^ ]方法。

然后,您需要将十进制值转换回字符串。再一次,简单 - 只需使用 decimal.ToString [ ^ ]方法,带有适当的格式字符串:

< pre lang =text>0,0.00

会这样做 - 它指定数千应该用逗号分隔,并且应该总是有两个小数位。



这不应该超过五分钟! :笑:


我按照我的需要做了以下几点。对你们所有人表示感谢。



Convert.ToDecimal(TextBox1.Text).ToString(0.00);

Hi fellows,

need your kind help.. I m having a textbox and want to convert its string value on a lable like below.

string.00

for exmple in texbox there is a value 125 than on lable it should be a decimal value like 125.00



Kindly help.

解决方案

Try:

myLabel.Text = myTextBox.Text + ".00";




But i wanted to do that with .ToDecimal() method... can you help me??


That sound like homework! :laugh:

So, no code...but it isn''t difficult at all.
The first thing you need to do is convert the string value in your text box to a decimal value. Tht''s easy: Use the decimal.Parse[^] or decimal.TryParse[^] methods.
Then, you need to convert the decimal value back to a string. Again, easy - just use the decimal.ToString[^] method with an appropriate format string:

"0,0.00"

will do it - it specified that thousands should be separated by commas, and there should always be two decimal places.

This shouldn''t take you more than five minutes! :laugh:


I did the following as per my need. and it rocks.. Thanks alot to all of YOU.

Convert.ToDecimal(TextBox1.Text).ToString("0.00");


这篇关于如何使用字符串值添加.00。小数点最多两个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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