Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 170875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:53:13+00:00 2026-05-11T12:53:13+00:00

I want to be able to write a function which receives a number in

  • 0

I want to be able to write a function which receives a number in scientific notation as a string and splits out of it the coefficient and the exponent as separate items. I could just use a regular expression, but the incoming number may not be normalised and I’d prefer to be able to normalise and then break the parts out.

A colleague has got part way of an solution using VB6 but it’s not quite there, as the transcript below shows.

cliVe> a = 1e6 cliVe> ? 'coeff: ' & o.spt(a) & ' exponent: ' & o.ept(a) coeff: 10 exponent: 5  

should have been 1 and 6

cliVe> a = 1.1e6 cliVe> ? 'coeff: ' & o.spt(a) & ' exponent: ' & o.ept(a) coeff: 1.1 exponent: 6 

correct

cliVe> a = 123345.6e-7 cliVe> ? 'coeff: ' & o.spt(a) & ' exponent: ' & o.ept(a) coeff: 1.233456 exponent: -2 

correct

cliVe> a = -123345.6e-7 cliVe> ? 'coeff: ' & o.spt(a) & ' exponent: ' & o.ept(a) coeff: 1.233456 exponent: -2 

should be -1.233456 and -2

cliVe> a = -123345.6e+7 cliVe> ? 'coeff: ' & o.spt(a) & ' exponent: ' & o.ept(a) coeff: 1.233456 exponent: 12 

correct

Any ideas? By the way, Clive is a CLI based on VBScript and can be found on my weblog.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T12:53:14+00:00Added an answer on May 11, 2026 at 12:53 pm

    Google on "scientific notation regexp" shows a number of matches, including this one (don’t use it!!!!) which uses

    *** warning: questionable *** /[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?/ 

    which includes cases such as -.5e7 and +00000e33 (both of which you may not want to allow).

    Instead, I would highly recommend you use the syntax on Doug Crockford’s JSON website which explicitly documents what constitutes a number in JSON. Here’s the corresponding syntax diagram taken from that page:

    alt text
    (source: json.org)

    If you look at line 456 of his json2.js script (safe conversion to/from JSON in javascript), you’ll see this portion of a regexp:

    /-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/ 

    which, ironically, doesn’t match his syntax diagram…. (looks like I should file a bug) I believe a regexp that does implement that syntax diagram is this one:

    /-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+\-]?\d+)?/ 

    and if you want to allow an initial + as well, you get:

    /[+\-]?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+\-]?\d+)?/ 

    Add capturing parentheses to your liking.

    I would also highly recommend you flesh out a bunch of test cases, to ensure you include those possibilities you want to include (or not include), such as:

    allowed: +3 3.2e23 -4.70e+9 -.2E-4 -7.6603  not allowed: +0003   (leading zeros) 37.e88  (dot before the e) 

    Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 212k
  • Answers 212k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer To answer your first question: If it's quite likely the… May 12, 2026 at 10:21 pm
  • Editorial Team
    Editorial Team added an answer It is absolutely necessary for both the page with the… May 12, 2026 at 10:21 pm
  • Editorial Team
    Editorial Team added an answer Multiply one with a high enough value SELECT id1 *… May 12, 2026 at 10:21 pm

Related Questions

I'm aware that fold-left produces left-leaning trees and fold-right produces right-leaning trees, but when
I want to write documentation on my pet project. I have 30 tables and
I'm new to object oriented programming and flash. As far as I know, global
I am trying to write a view that will generate a report which displays

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.