how to force decimals to display in exponential notation

Discussion in 'ASP General' started by revansx@cox.net, Oct 15, 2006.

  1. Guest

    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
     
    , Oct 15, 2006
    #1
    1. Advertising

  2. Guest

    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

    > wrote:
    > > 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.
     
    , Oct 16, 2006
    #2
    1. Advertising

  3. wrote:
    > 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.

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Oct 16, 2006
    #3
  4. wrote:
    > 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>



    --
    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.
     
    Dave Anderson, Oct 16, 2006
    #4
  5. Guest

    perfect!
    many thanks,

    cheers!
    - rich
     
    , Oct 16, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Timothy Fitz

    Exponential Notation and integers

    Timothy Fitz, Nov 18, 2004, in forum: Python
    Replies:
    4
    Views:
    1,079
    =?ISO-8859-1?Q?F=E1bio?= Mendes
    Nov 19, 2004
  2. Grey Squirrel

    Hungarian Notation Vs. Pascal Notation?

    Grey Squirrel, Mar 19, 2007, in forum: ASP .Net
    Replies:
    6
    Views:
    1,334
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider]
    Mar 21, 2007
  3. Tameem
    Replies:
    454
    Views:
    12,216
  4. Robert Mark Bram

    Dot notation V Bracket notation

    Robert Mark Bram, Jul 4, 2003, in forum: Javascript
    Replies:
    3
    Views:
    475
    Robert Mark Bram
    Jul 5, 2003
  5. J.Sperlhofer
    Replies:
    9
    Views:
    297
    Dr John Stockton
    Apr 28, 2005
Loading...

Share This Page