locked
round automatically 3 digit decimal RRS feed

  • Question

  • User-807418713 posted

    Hi

    I have one textbox i enter value like this

    0.3 on button click i want to show 0.300

    again for example i enter 0.34

    on button click i want to show 0.340

    how to do so using asp.net c#

    Thursday, January 14, 2021 11:20 AM

Answers

  • User-1716253493 posted
        protected void Button1_Click(object sender, EventArgs e)
        {
            TextBox1.Text = string.Format("{0:N3}", Convert.ToDouble(TextBox1.Text));
        }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 14, 2021 2:53 PM

All replies

  • User-1545767719 posted

    You will have to learn javascript or C#. ASP.NET does not matter.

    Thursday, January 14, 2021 12:29 PM
  • User475983607 posted

    Hi

    I have one textbox i enter value like this

    0.3 on button click i want to show 0.300

    again for example i enter 0.34

    on button click i want to show 0.340

    how to do so using asp.net c#

    I recommend trying to write the code yourself.   You have a lot of posts on these forums and most of the time you are looking for the community to write your code.

    On the C# side it is simple as declaring a decimal type and applying a numeric format.   See the docs.

    https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings

    If you need a JavaScript solution then see the following.

    https://www.w3schools.com/jsref/jsref_tofixed.asp

    Thursday, January 14, 2021 12:35 PM
  • User-1716253493 posted
        protected void Button1_Click(object sender, EventArgs e)
        {
            TextBox1.Text = string.Format("{0:N3}", Convert.ToDouble(TextBox1.Text));
        }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 14, 2021 2:53 PM