Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
MikerRoo #1
Need to format numbers with scientific and engineeringformats.
Hi,
Does anybody have a recipe for forcing scientific notation? Maybe something like C's sprintf function ...
EG: "sprintf (buffer, "%5.3E", ...);"
Thanks,
-- MikeR
MikerRoo Guest
-
scientific calculation in flash?
can I implement some scientific calculation in flash? I mean , can I write a public method, e.g. calculate(dataId), and call it from JavaScript and... -
Howto cite postgresql in scientific publications?
Hi, Is there an official way to cite PostgreSQL in scientific publications? This might sound somewhat strange to some of you, but e.g. the R... -
FREE! 1000+ Scientific Symbols for Illustrator
Very good info...thanks. On a related topic, does anybody know a good site to get "landscape design" symbols? I'm talking about the symbols... -
format numbers with parentheses
Hi all, I want to format right-aligned positive and negative numbers in a grid. My problem is that I want the negs in parentheses, which is... -
Numerical/Scientific programming ruby group
Hi Gordon, Gordon James Miller wrote: I'd be vaguely interested in this, because I've been doing a lot of numerical stuff at uni lately. I... -
PaulH #2
Re: Need to format numbers with scientific andengineering formats.
maybe overkill for you but i've used java.text.DecimalFormat for that in i18n apps.
PaulH Guest
-
MikerRoo #3
Re: Need to format numbers with scientific andengineering formats.
Thanks, Paul.
The JAVA version of DecimalFormat() looks like it would be an improvement.
But I can't get it to work.
For example when trying to use one of the format functions, like:
<CFSET zJ_Txt = CreateObject("Java","java.text.DecimalFormat")>
<h3>Attempt2 to format = #zJ_Txt2.format (JavaCast ("double",
123.4567890001))#.</h3>
I get:
" The selected method format was not found.
Either there are no methods with the specified method name and argument types,
or the method format is overloaded with arguments types that ColdFusion can't
decipher reliably. If this is a Java object and you verified that the method
exists, you may need to use the javacast function to reduce ambiguity."
I only seem to be able to use the non-overloaded functions, like toPattern().
Regards,
-- MikeR
MikerRoo Guest
-
PaulH #4
Re: Need to format numbers with scientific andengineering formats.
sorry it's been so long that i had to struggle w/the internals of this sort of
thing (it's all buried in a CFC) i forgot you have to write wrappers for all
the numerical format() methods. see the code below (i ripped out the i18n bits
but haven't tested it,so double check). compile it and toss the .class file
into your cf_Install\wwwroot\WEB-INF\classes dir.
import java.text.DecimalFormat;
import java.text.NumberFormat;
public class scientificFormat {
public final static String scientificFormatter(Double thisNumber, String
thisPattern) {
NumberFormat dF = new DecimalFormat(thisPattern);
String scientificStr= dF.format(thisNumber);
return scientificStr;
}
}
PaulH Guest
-
MikerRoo #5
Re: Need to format numbers with scientific andengineering formats.
Thanks, Paul.
It worked.
-- MikeR
MikerRoo Guest
-
PaulH #6
Re: Need to format numbers with scientific andengineering formats.
btw that's going to return formatting based on your server's default locale, so
look at that if it starts throwing crazy stuff back at you if you move the app.
and while i'm thinking about this if you need more ganular control over
rounding, padding, and significant digits you might want to look at icu4j's
DecimalFormat class intead of the core java class (that's actually what we used
but we use that IBM lib for all our i18n stuff).
PaulH Guest
-
MikerRoo #7
Re: Need to format numbers with scientific andengineering formats.
Thanks again, Paul.
I had figured out the locale stuff when I looked up DecimalFormat. That and
the instruction to compile your own java class was the key advice. (I had no
clue what java's formatting functions were (We bought CF so we wouldn't have to
use java :P )).
DecimalFormat () is actually perfect for now (with a few custom post-string
tweaks).
For future reference, I've since discovered that Sun replicates the full
sprintf functionality with its PrintfFormat class and Henrik Bengtsson has
replicated the sprintf family nicely in java.
Regards,
-- MikeR
MikerRoo Guest
-
PaulH #8
Re: Need to format numbers with scientific andengineering formats.
i'm not familiar w/PrintfFormat (and i don't see it in the API for 1.4 or 1.5).
what package is that in?
just in case you haven't thought about this already, users have the pesky
habit of wanting you to
parse those fancily formatted numbers your app produces back into something
suitable for a db, etc. which is nearly impossible in many cases if your
formattng strays very far from the "standards".
PaulH Guest
-
MikerRoo #9
Re: Need to format numbers with scientific andengineering formats.
PrintfFormat is not in a package. It's an add-on class that Sun provides to
appease C programmers.
More information can be found at
[url]http://java.sun.com/developer/technicalArticles/Programming/sprintf/[/url]
I know all about having to endlessly tweak report and number formats.
However, my shop is lucky in that we don't have to do any internationalization.
In fact, our guy, Calvin, says that when he's in charge, there will be only
one locale and everyone will speak esperanto.
MikerRoo Guest
-
PaulH #10
Re: Need to format numbers with scientific andengineering formats.
well we don't endlessly tweak formats. if the data has to be two-way we (via
our i18n CFC) only allow formatting using 1 of the 4 standard styles (which
parses easily enough), if its really customized its only one way ;-)
esperanto? well it is recognized as a genuine language by the CLDR project but
i don't see any locales in core java or icu4j (via getAvailableLocales) for it.
i guess your friend has a tough row to hoe.
and thanks for the link, i'll have a closer look at it. did java 1.5 add
anything for this? i seem to recall something about formatting messages or
something along those lines.
PaulH Guest
-
MikerRoo #11
Re: Need to format numbers with scientific andengineering formats.
Don't know if java 1.5 made any improvements in this area. I do know that
classes compiled with the 1.5 SDK are incompatible with CF 7 (except that I
didn't try running enterprise on a 1.5 App server -- since our production
server, in this case, is running the CF standard edition).
Trying to use 1.5 or SDK 5 classes resulted in JRUN "major/minor version"
errors. We reverted to SDK 1.4.2 and left it at that.
Anyway this fire's out. Thanks for your help.
MikerRoo Guest



Reply With Quote

