Displaying a number as TWO DIGITS - ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a page that is pulling a field value from a database.

I want to be able to change any one-digit numbers that get returned as
TWO-DIGIT numbers (example: 0 would come back as 00, 1 would come back as 01,
etc).

Is there a simple way to do this? (I'm using FrontPage and ASP...and am a
extreme beginner.) Thanks for your help!
 
I figured it out! Just wanted to post it here in case it's a help to anyone
else, at some point. (Turns out that my initial mistake was leaving out a
"&" in the concatenation when displaying the results.)

-- Nate
-------------------------

<%
Minutes50FreeBoys=FP_FieldVal(fp_rs,"Minutes_Freestyle50yd")

Seconds50FreeBoys=FP_FieldVal(fp_rs,"Seconds_Freestyle50yd")

Hundredths50FreeBoys=FP_FieldVal(fp_rs,"Hundredths_Freestyle50yd")

If Seconds50FreeBoys < 10 Then Seconds50FreeBoys = "0" + Seconds50FreeBoys

If Hundredths50FreeBoys < 10 Then Hundredths50FreeBoys = "0" +
Hundredths50FreeBoys
%>

<%
=Minutes50FreeBoys & ":" & Seconds50FreeBoys & "." & Hundredths50FreeBoys
%>
 
Glad to see you solved it!

Just to show you another method, you could also use a function to "pad"
digits with leading zeros. See the examples at
http://classicasp.aspfaq.com/general/how-do-i-pad-digits-with-leading-zeros.html

With this you'd change your code to:

<%
Function PadDigits(n, totalDigits)
PadDigits = Right(String(totalDigits,"0") & n, totalDigits)
End Function

Minutes50FreeBoys = FP_FieldVal(fp_rs,"Minutes_Freestyle50yd")
Seconds50FreeBoys = PadDigits(FP_FieldVal(fp_rs,"Seconds_Freestyle50yd"), 2)
Hundredths50FreeBoys =
PadDigits(FP_FieldVal(fp_rs,"Hundredths_Freestyle50yd"), 2)

<%=Minutes50FreeBoys & ":" & Seconds50FreeBoys & "." &
Hundredths50FreeBoys%>

In this example we're saying that we want the value to have 2 digits. If it
doesn't then it adds a 0. If you wanted 3 zeros then you'd change the above
to 3.

By using functions like this you can cut down on the lines of code you need.
 
Back
Top