WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Numbers

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Floating point to HUGE numbers

#DefineFunction UDFCvtFloatToHuge(f)
   ;This UDF converts a floating point number to a
   ;high-precision decimal number sutiable for use
   ;by the hugemath extender.

   ;normalize number convert the "E" to uppercase just in case
   fupper=strupper(f + 0.0)
   ;get stuff in front of the E
   f1=ItemExtract(1,fupper,"E")
   ;get stuff behinf the E
   f2=ItemExtract(2,fupper,"E")
   ;If there is no E just return the number as is
   if f2=="" then return(f1)

   ;figure  out if the number is negative or not
   neg=@false
   if f1<0
      ;If the number was negative, remember that fact
      ;and convert it to a positive number
      neg=@TRUE
      f1 = -f1
   endif

   ;remove the .  Assume we are dealing with a normal
   ;scientific notation number where it looks like x.xxxxEyyy
   ;with just one digit in fron of the decimal.  Adding the
   ;0.0 in the first step will automagically normalize
   ;numbers that are not passed in normalized.
   f1=StrReplace(f1,".","")   ; remove .

   if f2<0
     ;if exponent (E Number) is negative, add zeros in front
      f1=strcat("0.",strfixleft(f1,0,-(f2)+strlen(f1)-1))
   else
      ;exponent is positive.  Add zeros behind
      f1=strfix(f1,0,max(strlen(f1) , f2+1))
   endif

   if neg==@FALSE then return(f1)
   else return (strcat("-",f1))
  
#EndFunction


    fnum=54321.0E12 
    testhuge=UDFCvtFloatToHuge(fnum)
    Pause(fnum,testhuge)

    fnum=123
    testhuge=UDFCvtFloatToHuge(fnum)
    Pause(fnum,testhuge)


Article ID:   W15003
File Created: 2001:11:08:12:41:20
Last Updated: 2001:11:08:12:41:20