Digging out old gems

Started by spl, June 11, 2026, 01:02:35 PM

Previous topic - Next topic

spl

have to go back over a decade, but I remember issues with converting scientific notation to decimal with excel and other data. WB made the conversion easy. Below is a stab from the past
;uncomment each to test
;sci = "5.7303333333e+02"
sci = "9.87E-02"
;sci = "6.022E23"  ;too large will fail, but can be done with MSScriptControl.ScriptControl
num = sci + 0 ;convert to decimal
Message("Result", sci:@lf:num)

;for very large values, like the one above that fails
sci = "6.022E23"
oS = CreateObject("MSScriptControl.ScriptControl")
oS.Language = "VBScript"
oS.AllowUI = @FALSE
num=oS.Eval(: 'FormatNumber(%sci%,0,,-1)')
oS = 0
Message("Result", sci:@lf:num)
Exit
Stan - formerly stanl [ex-Pundit]

td

You can do the same thing with a HughMath extender. A conversion UDF can be found here.

https://docs.winbatch.com/mergedProjects/HUGEMATH/HUGEMATH/HUGEMATH_U__001.htm

You can convert to a comma seperated integer using the HugeMath options function:
AddExtender("WWHUG44I.DLL", 0 , "WWHUG64I.DLL")
fnum=6.022E23
num=UDFCvtFloatToHuge(fnum)
huge_SetOptions (1, 0, 0, 1, 0, 0, 0)
num=huge_Add(num,0)

Pause(fnum,num)
exit


Admittedly, the "MSScriptControl.ScriptControl" solution is simpler. Just throwing up an alternative to avoid doing any real work this morning.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

spl

It is worth considering how the optional parameters for NumberFormat work. The first parm should consider the number of decimal places to the right, the last, if -1 will include the negative number in parenthesis.

if sci = "6.022E-06"
num=oS.Eval(: 'FormatNumber(%sci%,0,,0)') ; gives 0
num=oS.Eval(: 'FormatNumber(%sci%,6,,0)') ; gives 0.000006

;Parentheses only visible with actual negative numbers, so
;if  sci = "-6.022E-06"
num=oS.Eval(: 'FormatNumber(%sci%,6,0,-1)') ; gives (.000006)
Stan - formerly stanl [ex-Pundit]

SMF spam blocked by CleanTalk