I can't find how to do it. I would like the number to be displayed three decimal places. But to be remembered the whole number. Example: full number: 8658,645851243511447358350. Only display in TextBox: 8658,646 How should I do it? The point is that in the program code read number from TextBox was whole: 8658,645851243511447358350. I apologize if there is this solution somewhere. C# WinForms.
Asked
Active
Viewed 164 times
-1
-
Could you show your code?? – Jeffery Dec 09 '21 at 09:06
-
Does this answer your question? [How to format a Windows Forms Textbox with thousand separator and decimal separtor for numeric input](https://stackoverflow.com/questions/15473216/how-to-format-a-windows-forms-textbox-with-thousand-separator-and-decimal-separt) – Mark Benningfield Dec 09 '21 at 09:08
-
https://stackoverflow.com/a/68444096/14171304 – dr.null Dec 09 '21 at 09:50
-
dr.null's suggestion looks cool. I have a question why is res % 1 != 0? Could you please explain? – Wieslaw Dec 10 '21 at 06:47
-
Just to know whether the entered value is int or float. `res % 1` returns the fractions part if any otherwise 0. – dr.null Dec 10 '21 at 07:37
-
1dr.null thanks. This works really well. I still need to test and adjust so that the entry into the field shows the whole number, and the exit from the field shows the number formatted to the number of decimal places. It looks like it is already working according to these conditions. – Wieslaw Dec 10 '21 at 07:53
2 Answers
0
if this helps, you can use the "tag" property to store the full value, i.e.
TextBox.Text = "8658,646"
TextBox.Tag = "8658,645851243511447358350"

Peter Csala
- 17,736
- 16
- 35
- 75

Marcin
- 1
0
I got a workaround and that is to create your own class and that add additional property i.e., FullValue
and keep track of both formatted and full value.
public class CustomTextBox:TextBox{
public string FullValue{get;set;}
}
or you can do
public class CustomTextBox:TextBox{
private string _FullValue;
public string FullValue{get=>_FullValue;set{base.Text=value;_FullValue=value;}}
}

Arham Anees
- 112
- 9