简体   繁体   English

格式化文本框以在运行时以带小数的千位分隔符的形式显示用户输入

[英]Format a text box to display user input on runtime in form of thousand separator number with decimals

i am still new to c#, i am trying to build a simple calculator with c# windows form.我还是 c# 的新手,我正在尝试使用 c# windows 形式构建一个简单的计算器。 i did all the coding but i am stuck in formating my calculator screen(text box in this case) to display numbers with thousand separator comma and decimal point.我做了所有的编码,但我被困在格式化我的计算器屏幕(在这种情况下为文本框)以显示带有千位分隔符逗号和小数点的数字。

for example: if the user input 1000 i want it to display 1,000 of if the user input 1000.0123 i want it to display 1,000.0123 on the fly(just like the windows 10 calculator)例如:如果用户输入 1000 我希望它显示 1,000 如果用户输入 1000.0123 我希望它即时显示 1,000.0123(就像 windows 10 计算器一样)

i really appreciate the any help, i have been searching all around the internet for some solution and came to nothing我真的很感谢任何帮助,我一直在互联网上搜索一些解决方案,但一无所获

use string format, in the textbox where you show the numbers:在显示数字的文本框中使用字符串格式:

txtNumber.text = string.Format("{0:n}",12521452.646521); // 12,521,452.64

or:或者:

txtNumber.text = string.Format("{0:#,0.#########}", 12521452.646521))   // 12,521,452.646521

see more: C# String Format Method查看更多: C# 字符串格式方法

var input = 1024.10;
Console.WriteLine(input.ToString("N"));

Output: Output:

1,024.10 1,024.10

Format as a numeric value with 2 decimal places.格式为带有 2 位小数的数值。 For 3 or 4 decimal places you can use ToString("N3") or N4.对于 3 或 4 位小数,您可以使用 ToString("N3") 或 N4。 For No decimal places ToString("N0")对于没有小数位 ToString("N0")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 带前导零和千位分隔符的格式编号 - Format number with leading zeros and thousand separator Json 无千位分隔符的数字字符串格式 - Json Number String Format Without Thousand Separator 如何在本地化的千位分隔符中格式化数字以保持小数位相同? - How to format a number in localized thousand separator keeping the decimal digits the same? 使用 NPOI 以印度风格显示带有千位分隔符的数字 - Display a number with thousand separator in Indian style using NPOI 格式化Windows窗体文本框显示 - Format Windows Form Text Box Display 将double转换为带有N个小数的字符串,点作为小数点分隔符,没有千位分隔符 - Converting double to string with N decimals, dot as decimal separator, and no thousand separator 更改显示格式数字小数点分隔符 - Change display format number decimal separator 如何格式化窗口形式文本框具有千位分隔符和十进制separtor用于数字输入 - how to format a windows forms Textbox with thousand separator and decimal separtor for Numeric input C#中1000,000格式的自定义数字组(千位分隔符) - Custom number group (thousand separator) for 1000,000 format in c# 从转换为文本格式的 PDF 中以逗号作为千位分隔符提取美元价格和数字 - Extracting dollar prices and numbers with comma as thousand separator from PDF converted to text format
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM