how to force decimals to display in exponential notation

R

revansx

Hi folks,

I am programming a page that displays scientific data retrieved from a
data source to an asp-web page and i would like to force all number to
be formatted/displayed in scientific notation no matter what the value
is. (i.e. x = 123 would be displayed as x = 1.23e+02). The standard
function "formatnumeric(x[,n])" does not seem to be able to do this for
me or at least I don't know how to use it that way.

Can anyone show mw a way?

thanks!
-rich evans
 
R

revansx

Hi Dave,

Thanks for the quick reply.

Isn't JScript a client-side scripting language?
I really need to be able to do this on the server-side.
....or did I misunderstand your solution?


- rich
I am programming a page that displays scientific data retrieved from a
data source to an asp-web page and i would like to force all number to
be formatted/displayed in scientific notation no matter what the value
is. (i.e. x = 123 would be displayed as x = 1.23e+02). The standard
function "formatnumeric(x[,n])" does not seem to be able to do this
for me or at least I don't know how to use it that way.

Can anyone show mw a way?

http://msdn.microsoft.com/library/en-us/script56/html/7c4a6d84-3c1f-4cc4-a67d-7753e5d4ed66.asp


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
 
B

Bob Barrows [MVP]

Hi Dave,

Thanks for the quick reply.

Isn't JScript a client-side scripting language?

No. JScript is a scripting language.
ASP support several scripting languages, including vbscript and jscript,
as well as others. See this for tips:
http://www.aspfaq.com/show.asp?id=2045

It is really incorrect to use "javascript" interchangeably with
"client-side script". IE supports the use of both vbscript and jscript
in client-side script. Other browsers only support javascript ... hence
the propensity for using the terms interchangeable.
I really need to be able to do this on the server-side.
...or did I misunderstand your solution?

Yes. He intended you to implement it in a server-side script block.
 
D

Dave Anderson

Isn't JScript a client-side scripting language?
I really need to be able to do this on the server-side.
...or did I misunderstand your solution?

JScript is availabel as a scripting language in ASP. I use it exclusively.

Now, I am not saying you need to change languages (though I think the
benefits of using JScript for ASP are many). ASP actually allows you to use
both languages in the same script. There are some rules to keep in mind,
however.

To begin with, understand that there are three distinctly different types of
scripting blocks:

1. <script runat="server" language="jscript"> ... </script>
2. <script runat="server" language="vbscript"> ... </script>
3. <% ... %>

I will refer to #3 as "inline" from here on.

When the script is parsed, the parser determines the language for inline
scripting, then executes the blocks in the following order: 1-3-2 (if inline
language is VBScript), or 2-3-1 (if JScript). HOWEVER, any block can call a
function from any other block. It does not matter what order the blocks
appear within the script.

If you want to mix-and-match languages, then, it is a good practice to
encapsulate the cross-language bits in functions:

<%@Language=VBScript%><%

Randomize
Dim N : N = 100 * Rnd()
Response.Write(FormatEXP(N,10))

%>
<script runat="server" language="jscript">
function FormatEXP(n,d) {
return n.toExponential(d)
}
</script>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top