You must Sign In to post a response.
  • Category: ASP.NET

    How To Insert TextBox Value Like 0000.00 Instead Round Of the Text Box Value

    Hi Developers,
    I am Created a project and round of Some values.

    Round of is Working fine
    if i am Inserting in a Text Box value Like 1234.65 na it gives exact output like 1235. Fine .
    But when i am Inserting the same Text Box value only Like this (0000.00) it throws the following error. This functionality is the very Important one of my Project.

    Index was outside the bounds of the array.

    Line 25: double num1 = Convert.ToDouble("0." + str[1]);

    My using Source Code is Below

    double a = Convert.ToDouble(txt1.Text);
    string[] str = a.ToString().Split('.');
    double num1 = Convert.ToDouble("0." + str[1]);
    double res;
    if (num1 < 0.51)
    res = Math.Floor(a);
    res = Math.Round(a);

    I can't able to resolve this error
    So please help me to i am clear the error.

    Thanks with
  • #765326
    I got Exact output for my 0000.00 Error Friends.

    Thanking you

  • #765328
    Hi Paul,

    If you want to Round off the decimal points, why are you doing this much of stuff? simply use Math.Round function and pass how many decimal points you want to Round off.



    Use above sample for rounding the decimal points, coming back to your error "Index was outsides the bounds of the array", the reason behind this error is you are accessing the outside range index; at that time you got this type of error.

    Hope this will helpful to you...

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #765351
    Thanks for your reply Mr.Naveen

  • Sign In to post your comments