1.e-004. I want to get rid of these numbers.

Blitz3D Forums/Blitz3D Programming/1.e-004. I want to get rid of these numbers.

Skitchy(Posted 2003) [#1]
Does anybody have a simple way of getting these small numbers back to the way they're written normally. Sorry, I can't remember the maths term for this (is it exponent?).

For example
x#=0.0001
print x

will yield a result of 1.e-004

"So what's your problem with that", you might say.

Well, I'm dealing with a .x file exporter that doesn't like numbers unless they're expressed as x.xxxxxxx. It doesn't like all this 'e-' stuff.

So if I do
VerySmallNumber#=0.00001
Writeline(file,VerySmallNumber#)
everything gets messed up.

I'm sure there must be a simple way - I'm just not seeing it. Any suggestions?

ATM, I'm thinking about multiplying by 1000, converting to a string, then hacking the decimal point back into the right position, but that seems like a VERY ugly workaround.

And don't say
If x<0.001 then x=0.001
I'm talking about lightmap UVs here which have to be between 0 and 1, so I can't afford to lose any precision.


Drago(Posted 2003) [#2]
num#=0.0000990123
bob$=Str(num)
bob2$=nonsci(num)
Print bob$+" "+bob2$
WaitKey

Function nonsci$(s#)
ss$=Str(s)
For a=1 To Len(ss)
m$=Mid(ss,a,1)
If m$="." dloc=a
If m$="e" Or "E"
	eloc=a
	zeros=Int((Mid(ss,a+2,3)))
EndIf
Next
If eloc=0 Return ss$
whole=Mid(ss,1,dloc)
point=Mid(ss,dloc+1,Len(ss))
For a=1 To zeros
If a=2 sss$=sss$+"."
sss$=sss$+"0"
Next
sss=sss+whole+""+point
Return sss
End Function


does this do what you want? btw this was a quick 5 min job. which is why the var names are strange ;) and no comments


Skitchy(Posted 2003) [#3]
That'll do it :)
I thought there might be some sort of 2 command way of doing it that I was overlooking but that's fine. I knocked one together as well, but I think yours is better
Here's mine :
x#=0.0000684
print x
print smalltostr(x)

Function SmallToStr$(in#)
If Abs(in)>=0.001 Then Return in
in=in*10000
tempstr$=Str(in)
length=Len(tempstr)
If Instr(tempstr,"-") Then sign$="-" Else sign$=""
temp2$=sign$+"0.000"
For counter=1 To length
f$=Mid$(tempstr$,counter,1)
If f$="1" Or f$="2"Or f$="3"Or f$="4"Or f$="5"Or f$="6"Or f$="7"Or f$="8"Or f$="9"Or f$="0"
	temp2$=temp2$+f$
EndIf
Next
;temp2$=Left(temp2$,8)
Return temp2$
End Function


Thanks for the help :)