Re: [flexcoders] NaN to return a string?
Turns out showing a zero could be implied that the calculation was a zero. This is bad, especially if the result is actually zero. Is there any way to return a string rather than a number? isNaN(mynumber) ? 0 : -- Blair Cox http://www.luminultra.com From: Sid Maskit [EMAIL PROTECTED] Reply-To: flexcoders@yahoogroups.com Date: Thu, 31 Jul 2008 07:51:38 -0700 (PDT) To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] NaN and Infinity showing in output - How to modify? If the format function is a custom function you have written, you could just have it check whether you like the result it is about to return, and if not, return something else. If that is not the case, I believe that you should be able to put tests into your binding statement. You could test for NaN with something like this: mx:Label text={(myNumber is NaN) ? 0 : PrepForDispl ay.format( myNumber) }/ I'm not sure about infinity, but I assume that you can test for this by looking for the greatest possible value of the number. Assuming that you have set up the variable maxValue to contain that value, you should be able to do something like this: mx:Label text={(myNumber maxValue) ? 0 : PrepForDispl ay.format( myNumber) }/ If you put the two together, it would look something like this: mx:Label text={(myNumber is NaN) ? 0 : (myNumber maxValue) ? 0 : PrepForDispl ay.format( myNumber) }/ Sid Maskit Partner CraftySpace Better Websites for a Better World http://www.CraftySpace.com blog: http://smaskit.blogspot.com/
Re: [flexcoders] NaN to return a string?
Sure, just replace the 0 with whatever text you want, putting it inside single quotes since the entire statement is inside of double quotes. Since you are setting the value of a label, what ever you put in is going to be cast to a string anyway. Sid Maskit Partner CraftySpace Better Websites for a Better World http://www.CraftySpace.com blog: http://smaskit.blogspot.com/ - Original Message From: Blair Cox [EMAIL PROTECTED] To: flexcoders@yahoogroups.com Sent: Thursday, July 31, 2008 9:27:02 AM Subject: Re: [flexcoders] NaN to return a string? Turns out showing a zero could be implied that the calculation was a zero. This is bad, especially if the result is actually zero. Is there any way to return a string rather than a number? isNaN(mynumber) ? 0 : -- Blair Cox http://www.luminult ra.com From: Sid Maskit [EMAIL PROTECTED] com Reply-To: [EMAIL PROTECTED] ups.com Date: Thu, 31 Jul 2008 07:51:38 -0700 (PDT) To: [EMAIL PROTECTED] ups.com Subject: Re: [flexcoders] NaN and Infinity showing in output - How to modify? If the format function is a custom function you have written, you could just have it check whether you like the result it is about to return, and if not, return something else. If that is not the case, I believe that you should be able to put tests into your binding statement. You could test for NaN with something like this: mx:Label text={(myNumber is NaN) ? 0 : PrepForDispl ay.format( myNumber) }/ I'm not sure about infinity, but I assume that you can test for this by looking for the greatest possible value of the number. Assuming that you have set up the variable maxValue to contain that value, you should be able to do something like this: mx:Label text={(myNumber maxValue) ? 0 : PrepForDispl ay.format( myNumber) }/ If you put the two together, it would look something like this: mx:Label text={(myNumber is NaN) ? 0 : (myNumber maxValue) ? 0 : PrepForDispl ay.format( myNumber) }/ Sid Maskit Partner CraftySpace Better Websites for a Better World http://www.CraftySp ace.com blog: http://smaskit. blogspot. com/
Re: [flexcoders] NaN to return a string?
Doh! Only way to get better at this is to keep working at it. Thanks for all three of your great suggestions. The powers that be want a note, so we¹ll go with that that. I¹ll find uses for the other options for sure. Cheers! -- Blair Cox From: Sid Maskit [EMAIL PROTECTED] Reply-To: flexcoders@yahoogroups.com Date: Thu, 31 Jul 2008 09:43:06 -0700 (PDT) To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] NaN to return a string? Sure, just replace the 0 with whatever text you want, putting it inside single quotes since the entire statement is inside of double quotes. Since you are setting the value of a label, what ever you put in is going to be cast to a string anyway. Try something like this: mx:Label id=display text={(isNaN(myNumber as Number)) ? 0 : PrepForDisplay.format(myNumber)} visible={display.text != '0' amp;amp; display.text != 'In,fin,ity.00'}/ Note that you need to give the Label component and id, and use that id to refer to it in your statements within braces. By the way, as you are no doubt noticing, the larger point here is that braces are not just for binding, but can contain all sorts of ActionScript. Finally, the reason that there is amp;amp; instead of is that we are inside of MXML, which is to say inside of XML, and we cannot use the character there, but must escape it. Sid Maskit Partner CraftySpace Better Websites for a Better World http://www.CraftySpace.com blog: http://smaskit.blogspot.com/