Re: Quick note about future number handling
Denis <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Le 20 mars 2010 à 08:53, Tom Fennelly a écrit :
>
> Daniel Dekany wrote:
>> Saturday, March 20, 2010, 2:33:18 AM, Brian Pontarelli wrote:
>>
>>
>>> I've run into issues over the past 4 years due to the default
>>> number handling in templates. The problem is regarding the
>>> difference between ${n} and ${n?c} and it has consistently been an issue.
>>>
>>> The problem is that testing generally doesn't find issues until
>>> database and other IDs exceed 1000 and FreeMarker begins to insert commas such as:
>>>
>>> 1,020
> Hi there.
>
> If you wanted to maintain backward compatibility, perhaps you could
> leave the default as is and provide a method on the
> Template/Configuration instance for overriding the default formatting.
> Could also do same with a new computer readable default, allowing
> existing users to override the default back to the old human readable
> default (which I've also found to be a total PITA :) ).
>
> In fact.... would this be nice to have for all types... including Dates
> etc e.g.
>
> configuration.setDefaultFormatting(Number.class, "c");
> configuration.setDefaultFormatting(Date.class, "string('yyyy-MM-dd')");
> // etc...
>
>
> Actually ... just looked at the API and it appears to already be there
> on the Configuration class i.e. setNumberFormat(String) and
> setDateFormat(String) :) Why did I never see that before :)
It is in the documentation:
http://freemarker.org/docs/pgui_config_settings.html
http://freemarker.org/docs/app_faq.html#faq_number_grouping (linked in the Built-ins for numbers page)
Simple code:
Environment env = myTemplate.createProcessingEnvironment(root, out);
env.setNumberFormat(env.getCNumberFormat());
env.process();
-- Denis.
>
> Regards,
>
> T.
>>
>>> I know there are a number of ideas floating about for an
>>> incompatible release (possibly 3.0) and I would like to toss this
>>> one in there.
>>>
>>> -bp
>>>
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev