Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing two numbers in a percentage format?

Status
Not open for further replies.

d1004

Programmer
May 9, 2002
78
0
0
US
In one of my page, I compare two numbers. For an example,
12.9% with 9.8%. If 12.9% is higher than 9.8%, then 12.9% is bolded, otherwise, 9.8% is bolded. But somehow, when my program compiles, it determine that 12.9% is smaller than 9.8%. Here is my code:

coYR47J78 = FormatPercent(coYR47J78,1)
coYR35G78 = FormatPercent(coYR35G78,1)


If coYR35G78 >= coYR47J78 Then


Response.write &quot;<td bgcolor = '#CCFFFF'> &quot; & coYR35G78 & &quot;<td>&quot; & coYR47J78 & &quot;<table>&quot;

Else

Response.write &quot;<td>&quot; & coYR35G78 & &quot;<td bgcolor = '#CCFFFF'>&quot; & coYR47J78 & &quot;</table>&quot;

End If

Does ASP has some kind of clitch when comparing percentage?

Thank you!!!
 
It appears to be a string equivalence rather tha numeric equivalence check (ie, the first character of 12.9% is less than the first character than 9.8%). You can use the FormatNumber function to return this value to numeric format for equivalence checks:
Code:
<%
Dim a, b
a = .05
b = .45
a = FormatPercent(a)
b = FormatPercent(b)
Response.Write &quot;<br>&quot;
Response.Write &quot;a% = &quot; & a & &quot;<br>b% = &quot; & b & &quot;<br>&quot;
If a > b Then
	Response.Write &quot;a% &gt; b%<br>&quot;
Else
	Response.Write &quot;a% &lt;= b%<br>&quot;
End If
Response.Write &quot;a = &quot; & FormatNumber(a) & &quot;<br>b = &quot; & Formatnumber(b)&&quot;<br>&quot;
If FormatNumber(a) > FormatNumber(b) Then
	Response.Write &quot;a &gtl b<br>&quot;
Else
	Response.Write &quot;a &lt;= b<br>&quot;
End If
%>

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
Why don't you try to use CDbl() to convert the converter value into a double precision numeric value.

coYR47J78 = CDbl(FormatPercent(coYR47J78,1))
coYR35G78 = CDbl(FormatPercent(coYR35G78,1))


If coYR35G78 >= coYR47J78 Then


Response.write &quot;<td bgcolor = '#CCFFFF'> &quot; & coYR35G78 & &quot;<td>&quot; & coYR47J78 & &quot;<table>&quot;

Else

Response.write &quot;<td>&quot; & coYR35G78 & &quot;<td bgcolor = '#CCFFFF'>&quot; & coYR47J78 & &quot;</table>&quot;

End If
 
I believe cDbl may complain about the formatting of the expression your giving it (percentage). Though IO could be wrong. I also believed the percentage format to be necessary.
-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top