Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

html format - currency, qty, date

Posted on 2010-01-04
6
Medium Priority
?
1,147 Views
Last Modified: 2012-08-14
I have a SQL application that sends email in html.  My problem is the format:

currency - I need it with dollar sign, two decimal places, right justified.  It currently has no dollar sign, no decimal places unless the value has them and is left justified.

qty - I need it right justified.  It currently is left justified

date - I need it in mm/dd/yy format.  Currently the month and day are one or two characters and the year is four characters.

Here is my code:

{BEGIN*HTML}
<table class='mytable'>
      <thead>
            <tr class='mytable'>
                  <th class='mytable'>Line</th>
                  <th class='mytable'>Delivery</th>
                  <th class='mytable'>Qty</th>
                  <th class='mytable'>Part Number</th>
                  <th class='mytable'>Description</th>
                  <th class='mytable'>Unit Price</th>
                  <th class='mytable'>Ent'd Price</th>
                  <th class='mytable'>Due Date</th>
            </tr>
      </thead>
      <tbody>
            {BEGIN*REPEAT}
            <tr class='mytable'>
                  <td class='mytable'>{Line}</td>
                  <td class='mytable'>{Delivery}</td>
                  <td class='mytable'>{Current_Qty}</td>
                  <td class='mytable'>{Part_Number}</td>
                  <td class='mytable'>{Description}</td>
                  <td class='mytable'>{Unit_Price}</td>
                  <td class='mytable'>{Extended_Price}</td>
                  <td class='mytable'>{Due_Date}</td>
            </tr>
            {END*REPEAT}
      </tbody>
</table>
{END*HTML}
0
Comment
Question by:ginsburg7
  • 4
  • 2
6 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 2000 total points
ID: 26176159
to right-align a pariticular cell you can declare a class on your css file/page section:
.rightAlign{text-align:right;}

then on what you posted, you add that class to the cell(s) in quesion:
{BEGIN*REPEAT}
            <tr class='mytable'>
                  <td class='mytable'>{Line}</td>
                  <td class='mytable'>{Delivery}</td>
                  <td class='mytable rightAlign'>{Current_Qty}</td>
                  <td class='mytable'>{Part_Number}</td>
                  <td class='mytable'>{Description}</td>
                  <td class='mytable'>{Unit_Price}</td>
                  <td class='mytable'>{Extended_Price}</td>
                  <td class='mytable rightAlign'>{Due_Date}</td>
            </tr>
            {END*REPEAT}

as for the date formatting and the number of decimals, you need to do so on the actual data source. What you posted is just an "template".

Open in new window

0
 

Author Comment

by:ginsburg7
ID: 26176338
That helps a little, but it seems every value is treated as text.  How do I tell it what is a number or date?
0
 
LVL 82

Expert Comment

by:hielo
ID: 26176409
>> How do I tell it what is a number or date?
You need to use the appropriate function. Assuming you have:
$total=3;

then
echo number_format($total, 2);//will change 3 to 3.00
http://us2.php.net/manual/en/function.number-format.php

For dates, you can use strtotime() to convert a string date to an actual date
$date="2009-07-12 12:00:00";

$actualDate=strtotime($date);

then use the date() function to reformat the actual date:
$purchaseDate = date('m/d/y',$actualDate);

You can of course combine date() and strtotime()::
$date="2009-07-12 12:00:00";
$purchaseDate = date('m/d/y', strtotime($date) )
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 82

Expert Comment

by:hielo
ID: 26176415
In case you need other formats, refer to:
date:
http://us2.php.net/manual/en/function.date.php

0
 

Author Comment

by:ginsburg7
ID: 26176435
In the database, the numbers fields are numbers and date fields are dates.  It's just when the html code is run it seems to convert numbers and dates to text.
0
 
LVL 82

Expert Comment

by:hielo
ID: 26176485
I don't know what db you are using, but most dbs have formatting functions. For example, if you are currently doing:
SELECT * FROM table...

you need to STOP that practice ( of using * instead of the field names) and actually name the fields:
SELECT price, quantity, total,... FROM Table...

So if in your db price is set to 1 but you want 1.00

then in mysql, you would use:
SELECT FORMAT(price,2) as price, quantity, total,... FROM Table...

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_format

Similarly, there is a formatting function for dates - date_format()
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format

If you are not using mysql, you just need to lookup the corresponding functions for your db.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question