Author Topic: Rounding Scientific Notation  (Read 2441 times)

0 Members and 1 Guest are viewing this topic.

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Rounding Scientific Notation
« on: October 16, 2018, 11:41:53 am »
Is there a way to round scientific notation to whatever number of decimal places you want? Here is an example however it's cumbersome and uses String variables. If I could I would like to stay with pure numeric values/variables.

  _FULLSCREEN

a = 52 / 3589
b = a * 100
c = INT(b)
d = b - c
e$ = STR$(d)
f$ = LEFT$(e$, 6)
f = VAL(f$)
g$ = RIGHT$(e$, 3)

PRINT
PRINT a
PRINT b
PRINT c
PRINT d
PRINT e$
PRINT f$
PRINT f
PRINT g$
IF VAL(g$) >= 500 THEN f = f + .0001
PRINT f

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Rounding Scientific Notation
« Reply #1 on: October 16, 2018, 11:46:55 am »
Check out Print Using: http://qb64.org/wiki/PRINT_USING

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Rounding Scientific Notation
« Reply #2 on: October 16, 2018, 12:57:10 pm »
Isn't this just a case of:

Result = INT(number * 10 ^ digits) / 10 ^ digits

For 2 decimal places:  X = INT(y * 100) / 100
For 3 decimal places:  X = INT(y * 1000) / 1000
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Re: Rounding Scientific Notation
« Reply #3 on: October 16, 2018, 04:41:55 pm »
Thanks guys, I can use both solutions. I appreciate the help.