If you want to display numbers from a database on your web page, chances are you will have to do some formatting to get your data to display the way you want it to. Here are a few examples.
<% Response.Write FormatDateTime(Date, vbShortDate) %> <% Response.Write FormatDateTime(Date, vbLongDate) %>
There are a lot of ways to display dates. The first line returns the short date in a format like this: “6/27/2015”. The second line returns the long date in a format like this: “Wednesday, June 17, 2015”.
<% Response.Write FormatDateTime(Time, vbShortTime) %> <% Response.Write FormatDateTime(Time, vbLongTime) %>
<% Response.Write FormatCurrency ( Variable, -1, -2, -2, -2) %>
When displaying currency, these are the system default settings.
- The first setting Variable contains the currency amount.
- The second setting is the number of decimal places.
- The third setting specifies not to use leading zeros for numbers less than one.
- The fourth setting specifies not to use parenthesis around negative numbers.
- The fifth setting specifies not to use a comma to separate number larger than one thousand.
The third, fourth, and fifth settings are in the “off” position by default. To turn these settings “on”, replace their respective -2 setting with a -1. To specify the number of decimals to use, simply change the second setting from -1 to whatever number you want.
<% Cint (Variable) %>
When displaying numbers, Cint displays the Integer subtype, which takes up 2 bytes in memory and can contain a value between -32,768 and 32,767.
<% Clng (Variable) %>
When displaying numbers, Clng displays the Long subtype which takes up 4 bytes in memory and can contain a value between -2,147,483,648 and 2,147,483,647.
<% Cdbl (Variable) %>
When displaying numbers, Cdbl displays the Double subtype, which takes up 8 bytes in memory, 4 bytes of which are used for containing fractional values. It is a very precise subtype used for advanced mathematical expressions including fractional or decimal values.
These are just a few of the most common techniques for formatting special data. Happy Formatting!