[pmwiki-users] Formatting numbers

John Rankin john.rankin at affinity.co.nz
Mon Jan 19 14:26:41 CST 2009


>Date: Sun, 18 Jan 2009 04:27:44 +0100
>From: Marcus <prima at wordit.com>
>Subject: [pmwiki-users] Formatting numbers
>
>Is there a way to format numbers?
>If I have a form variable "1.5", is there a way to add a zero *only*
>if the variable has one digit after the decimal point?
>
>1.5 becomes 1.50
>1.54 stays as 1.54
>
>Thanks,
>
>Marcus
>
You could experiment with a markup rule like this:

Markup('fmtzero','inline','/([\d]+\.\d)([^\d])/e',"'$1'.'0'.'$2'");

This might have strange side effects, like the pagename
Foo123.1Bar becoming Foo123.10Bar, so perhaps a more 
restrictive rule:

Markup('fmtzero','inline','/([\d]+\.\d)(\s)/e',"'$1'.'0 '");

Hope this helps.
-- 
John Rankin
Affinity Limited
T 64 4 495 3737
F 64 4 473 7991
021 RANKIN
john.rankin at affinity.co.nz
www.affinity.co.nz





More information about the pmwiki-users mailing list