On Thu, 20 Sep 2007 17:41:54 +1000, you wrote:

>Hi All,
>
>What's the best way to format a number with a fixed
>number of decimal places?
>
>For instance, if I have an Amount that I want to 
>format as dollars and cents, I'm currently using:
>
>begin immediate;
>create temporary table Invoice( Amount real );
>insert into Invoice values( 123.4 );
>select '$' || cast( Amount as integer ) || '.'
>       || substr( cast( Amount * 100 + 100 as integer ), -2, 2 )
>from Invoice;
>rollback;
>
>which gives:
>
>$123.40
>
>Is there a better way? I can't see any number formatting function in  
>SQLite's repertoire.

Round comes closest, but is not exacly what you need.
select '$' || round( Amount ,2) from Invoice;

Two remarks:
Formatting and presentation is usually considered a task of the
host language, not of SQL.
Valuta are best stored in integers (as cents).

>Thanks,
>Tom
-- 
  (  Kees Nuyt
  )
c[_]

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to