NumberFormat() mask bug?

100 views
Skip to first unread message

Adam Chapman

unread,
Jul 13, 2015, 1:46:07 AM7/13/15
to lu...@googlegroups.com
I would assume the code below should return 00, but Lucee 4.5 and 5 return a single 0. Coldfusion returns 00.

writeOutput(NumberFormat(0, 00));


Regards,
Adam


Adam Cameron

unread,
Jul 13, 2015, 1:50:18 AM7/13/15
to lu...@googlegroups.com
Yup: that's a bug.

 
Regards,
Adam


AJ Mercer

unread,
Jul 13, 2015, 2:19:37 AM7/13/15
to lu...@googlegroups.com
isn't the mask a string?

<cfscript>
writeOutput(NumberFormat(0, '00'));
</cfscript>


--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/639499f2-383c-4d6f-ae51-fbe18c7196f3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Adam Cameron

unread,
Jul 13, 2015, 2:56:44 AM7/13/15
to lu...@googlegroups.com


On Monday, 13 July 2015 07:19:37 UTC+1, AJ Mercer wrote:
isn't the mask a string?

<cfscript>
writeOutput(NumberFormat(0, '00'));
</cfscript>


writeOutput(NumberFormat(0, 00));


Ha! Didn't even notice that. More fool me for expected the repro case to be solid. Lesson learned.

-- 
Adam

Michael Offner

unread,
Jul 13, 2015, 3:02:10 AM7/13/15
to lucee
Nope, output is correct, the patten you pass (00) is a number not a string.
the numeric literal 00 is a valid numeric literal, but of course when the parser converts that literal to a number you end with 0 there is no number 00.
you need to pass this as literal string to get the expected result:
writeOutput(NumberFormat(0, "00"));

You get the expected result in ACF, because in ACF all literals get converted to strings by the parser, ACF converts all literals to Strings, take this example:
writeOutput(serializeJson( 00)); // output:"00"

This outputs "00" (with " around the numbers), because already the parser convert the literal to a string.

Or better take this example:
<cfscript>
n=0;
b=true;
s="";

writeOutput(n.getClass().getName());
writeOutput("<br>");
writeOutput(b.getClass().getName());
writeOutput("<br>");
writeOutput(s.getClass().getName());
writeOutput("<br>");
</cfscript>

this outputs in Lucee:
java.lang.Double
java.lang.Boolean
java.lang.String
and in ACF:
java.lang.String
java.lang.String
java.lang.String

Why ACF converts everything to a String is not clear to me, in Railo we decided from version 1 not to follow ACF on this for a simple reason.
When someone defines a number, he will mostly likely use it as a number, so we should keep it as a number.
In CFML it does mostly not matter what type it is (it does only in cases like this), but because it is faster to convert a number to a string than a string to a number, we decide to keep the type and not follow ACF on this.
When the json functions was introduced ACF had big problems, because they got outputs like the one above (" around literal numbers). They then added a patch for this that converts string that contains number to numbers, what is not really a good solution then this conversion cannot no, if string is by accident a string or not. take this example
writeOutput(serializeJson(0));
writeOutput(serializeJson("0"));
In that case the ACF parser converts the first literal to a string and the function serializeJson converts both inputs to numbers, so we get the output 
00
but it should be 
0"0"

maybe ACF 12 will fix this, because they plan to clean up, we will see.

Micha



 Micha






Adam Chapman

unread,
Jul 13, 2015, 5:22:07 AM7/13/15
to lu...@googlegroups.com

Thanks for the explanation..

*wraps 00 in quotes*


You received this message because you are subscribed to a topic in the Google Groups "Lucee" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lucee/j2UCyLmcPrU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lucee+un...@googlegroups.com.

To post to this group, send email to lu...@googlegroups.com.

Scott Conklin

unread,
Apr 27, 2016, 5:44:51 PM4/27/16
to Lucee

>> Why ACF converts everything to a String is not clear to me, in Railo we decided from version 1 not to follow ACF on this for a simple reason.
>> When someone defines a number, he will mostly likely use it as a number, so we should keep it as a number.

We have the case that ACF would not throw an error when using Numberformat with a negative number (where Lucee seems to insert a space between the number and the minus sign)
which in turn throws an error when performing a calculation on it.

<cfset ax = "-6.00" />

eg:

<cfset ax = NumberFormat(variables.tmp, '999,999.00') />
<cfset Form.V1S1 = (ax - ListLast(Form.VUA1))*ListFirst(Form.VUA1) />

has anybody else had this issue? 

Nando Breiter

unread,
Apr 27, 2016, 6:05:02 PM4/27/16
to lu...@googlegroups.com
I wouldn't depend on NumberFormat returning something that can be treated as a numeric in CFML. 

For instance, here in Switzerland, the thousands separator is an apostrophe. A VAT calculation like 

1'789.50 * 0.08 

will also throw an error. Format the number only for display. 



Aria Media Sagl
+41 (0)76 303 4477 cell
skype: ariamedia

--
Love Lucee? Become a supporter and be part of the Lucee project today! - http://lucee.org/supporters/become-a-supporter.html
---
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages