Reputation: 32911
I am using a custom validator to compare value in two text box. This is comparing the values fine. But it says "025" and "25" are different.. can this do a float comparision.
the custom validator i am using is
<asp:CompareValidator id="compval" runat="server" ControlToValidate="txtBox1"
ErrorMessage="There values are not equal."
Enabled="False" ControlToCompare="txtBox2">*</asp:CompareValidator></TD>
Please let me know if this is possible.
Upvotes: 1
Views: 4905
Reputation: 1739
I guess the following is what you need (the question could be phrased a little clearer)
<asp:CompareValidator ID="cv1" runat="server" ControlToCompare="txt1" ControlToValidate="txt2" Operator="Equal" Type="Integer" ErrorMessage="integers in txt1 and txt2 are not equal" />
Upvotes: 1
Reputation: 4364
The only thing I can think of without seeing your validation code is that 025 is being interpreted as an octal number (in C, putting a zero before an integer means it's in base 8). Then 025 would be 21 in base-10 and your two numbers wouldn't be the same.
I'm not sure how you'd come up with that, though. I tested out a few of the Parse() functions and they all convert the string "025" to base-10 25.
Upvotes: 1
Reputation: 15232
Use System.Double.Parse(value) to convert both to a floating point number, and compare those numbers.
You can also use TryParse if you don't want to handle exceptions if the value is not a valid floating point number.
See also:
Upvotes: 1