getting rid of "e" in x,y,z coordinates.

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
Old 01 January 2004   #1
getting rid of "e" in x,y,z coordinates.

getting rid of "e" in x,y,z coordinates
Wondering if someone could help me out with a Format problem. I'm printing out points to a file, but I don't want the exponential printed out. I've notice this occuring with very small numbers in Max. For example, [-86.6734,6.41911e-007,16.7711] where the y component in the list has an exponent. I was hoping there was some easy command to get rid of this exponent and force the number to print out in decimal form, but I haven't found anything. I was wondering if someone could point me in the right direction. Am I missing something big here?

I'm currently using a simple loop to decide if the number is smaller than a certain amount (let's say .00001 for example) if the number is smaller than that, then print out "0" in place of the exponential number.

if MyPoint.y < .00001 do
MyPoint.y = 0
print MyPoint.y

Surely, there must be an easier way than this. Or is everyone else using a loop to convert their exponential numbers. Anyone know of a way to completely convert without losing any precision in the exponential number given different exponential values. Say a function that takes [7.24311e-008, 6.41911e-007, 12] and converts to [0.000000724311, 0.00000641911, 12]. Any help would be greatly appreciated. Thanks.
Old 01 January 2004   #2
I don't think you'll be able to work with those as numbers (without the exponential notation), but since you're just going out to a file anyway you might try working with them as strings. It should be reasonably simple to write a function that converts, for instance, 7.24311e-008 to "0.0000000724311" as a string.

Of course, if you're going to be reading these values back into Max it will convert them to 0.0, so don't go to the extra trouble unless you're exporting for use elsewhere.

Got Maxscript?
Old 02 February 2004   #3
Hello LFShade, thanks for the reply. It was quite helpful. I know how to build a function that could convert
7.24311e-008 to "0.0000000724311" or any number that has an e-008 on the end of it. I'm not sure where to start when it comes to multiple different exponent numbers. Lets say you get the point set [7.243411e-008, 6.589346e-007, 3.142323]. Is there a blanket function that could address e-008 and e-007(and any other number with e^-nth power). Is there an "exponent-to- decimal" converter out there. Any rough ideas on where to start LFShade?
Old 02 February 2004   #4
Here's a function but it's a bit messy (just got home from the bar). I can't promise that it will work in all cases so make sure you test this a bit. If you make any changes or bug fixes please post them. I'm sure this can be simplified a bit more than this as well.

to use just call either

point3string <point3 value>
floatstring <float>

fn floatstring num =


	if num < 0.0001 or num > 999999.0 then


		numstr = num as string

		count = numstr.count


		-- grab mantissa 

		mantissa = substring numstr 1 (count - 5)

		-- grab sign from exponent append it to "1" and multiply by exponent

		if (substring numstr (count - 3) 1) == "-" then


			exponent = (-1 * ((substring numstr (count - 2) 3) as integer))




			exponent = ((substring numstr (count - 2) 3) as integer)


		-- adjust decimal place

		strout = ""		

		if mantissa[1] == "-" do

		( -- check to see if mantissa is negative

			strout += "-"

			mantissa = (substring mantissa 2 (mantissa.count - 1))


		-- locate decimal place

		decimal = findstring mantissa "."

		mantissa = (replace mantissa decimal 1 "")

		if exponent < 0 then


			strout += "0."

			for x in 0 to (abs(exponent) - decimal) do


				strout += "0"


			strout += mantissa




			-- account for decimal places moved by removing decimal from string

			mantcount = mantissa.count - (decimal - 1)

			strout += (replace mantissa 2 1 "")

			for x in 0 to (abs(exponent) - mantcount ) do


				strout += "0"


            		strout += ".0"


		return strout

	else return num			


fn point3string pt3
	return ("[ "+(floatstring pt3.x) + " , " + (floatstring pt3.y) " , " (floatstring pt3.z) + " ] ")
Old 02 February 2004   #5
RealThing thank you for putting up that very helpful code.
If you wrote that up in a drunken stupor, you must be extremely productive when you're sober! The code looks workable to me. I get the gist of what you're saying. You addressed some things I hadn't considered, such as creating a case where the decimal"." is eleminated if necessary and using substring to help filter through the string count.
Thanks again. Your help is greatly appreciate. It's good to have people like RealThing and LFShade on the forums.
Old 02 February 2004   #6
Here's a more string based approch...

Only evaluated when max is going to put that "e-" in your giddy-up... not tested THAT much, but seems to work well in one of my scripts...

fn ValuetoString Val =
ValasStr= (Val as string)
if ( findstring ValasStr "e-" != undefined ) then
Reform = filterString ValasStr "e-."
ValasStr = "0."
for i=1 to ((Reform[3] as integer)-1) do
ValasStr = ValasStr + "0"
ValasStr=ValasStr + ( Reform[1] + Reform [2] )



Keith Morrison

Last edited by Kramsurfer : 02 February 2004 at 06:26 PM.
Old 02 February 2004   #7
Looks good Keith. I would put a numeric test before converting all numbers to strings as this is a very slow process and should be avoided when possible.
Old 02 February 2004   #8
Actually now that I think about it in this case you have to convert the number to a string anyhow. So your method wouldn't be slow.
Old 02 February 2004   #9
yeah... true... That's what I was thinking... ha ha

Old 02 February 2004   #10
Hello KramSurfer. Thank you for sharing your code. I just glanced it over, but it looks just as valid. Lol, it's funny how people space their code though. I smush my stuff together like KramSurfer. RealThing's code is spacious. I guess it's easier to read it that way though...
It's interesting to see where key decisions are made in the two programs. RealThing creates a range bracket for numbers and then makes decisions. KramSurfer converts the numbers to text and then looks for the "e-". I love seeing the variety of approaches.
Old 02 February 2004   #11
I actually spaced my code out to make it easier to read in the message. I'm a fan of ";"'s and multi statment lines in ()'s for then and do loops.

I like my whole script, with 400+ commands, to fit on the screen at one time.. ha ha...

Old 01 January 2006   #12
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 02:30 AM.

Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.