numberFormat(foo/10^iif(fix(log10(abs(foo))) gt 1,
fix(log10(abs(foo))),fix(log10(abs(foo/10)))),"9.99")&"E"&iif(fix(log10(abs(
foo))) gt 1,fix(log10(abs(foo))),fix(log10(abs(foo/10))))
Ugly and ineffecient you say? I agree wholeheartedly.
Why log10 and not just len, other than simply the fact it counts +/- and .?
Soon as a number reaches float size CF represents it internally in E
notation w/ full precision.
Eg.
foo = "0.0000000000000000000000000424352353494";
writeOutput(val(foo));
I can't say I ever do anything in CF that uses any heavy math. CF just isn't
suited for it. I can't wait for CF5.0s UDFs to write function wrappers for
CFXs to extend it something akin to Perl's modules for extending it's
functions (haven't checked out CF5.0 other than reading a bit of the RC
release notes so I could be way off on how powerful UDFs will be).
If anyone knows a nicer way (there has to be one better than above) to
represent numbers in a consistant scientific notation it would be great.
-----Original Message-----
From: Howie Hamlin [mailto:[EMAIL PROTECTED]]
Sent: May 15, 2001 11:10
To: CF-Talk
Subject: Re: Scientific Notation Formatting
You can do something like:
<cfset num=260000000>
<cfoutput>#numberformat(num /
10^(len(num)-1),"9.9")#e#evaluate(len(num)-1)#</cfoutput>
Just bear in mind that this works for numbers >=1
HTH,
Howie Hamlin - inFusion Project Manager
On-Line Data Solutions, Inc.
www.CoolFusion.com
631-737-4668 x101
inFusion Mail Server (iMS) - The Intelligent Mail Server
----- Original Message -----
From: "Corina Moore" <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Tuesday, May 15, 2001 1:03 PM
Subject: Scientific Notation Formatting
> Anyone have any ideas on how to format a number using scientific Notation?
> For example I have the number 260000000000 and I want to display 2.6e11
>
> I would appreciate any help.
>
> Thanx
> *********************************
> Corina S. Moore
> IMDC Software Developer
> 301-286-6124
> http://imdc.nasa.gov
> **********************************
>
>
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists