Decimal places as needed

Decimal places as needed

Anonymous
Not applicable
575 Views
5 Replies
Message 1 of 6

Decimal places as needed

Anonymous
Not applicable
I read a vertex normal of a face in maxscript and it returns an array of 3 arrays like this:

#(, , )


this is ok but when I extract single numbers from each array and send it to output (just like below, example for one number only):


for i = 1 to theMesh.numfaces do
(
vertexNormal = meshop.getfaceRnormals theMesh i
format "%,%,%,%,%,%,%,%,%," vertexNormal.x vertexNormal.y vertexNormal.z vertexNormal.x vertexNormal.y vertexNormal.z vertexNormal.x vertexNormal.y vertexNormal.z to:outFile


I am getting the right numbers but all of them have decimal places like for example "0" is "0.0" and I want to shrink the file size as much as possible so where not needed I want maxscript not to put this unnecessary data:
0.0,-1.0,0.0,
0.0,-1.0,0.0,
0.0,-1.0,0.0


How do I do it?
0 Likes
576 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
Thats normal, as all Point3 values are Floats.
You can convert them to an Integers like this:
format "%,%,%,%,%,%,%,%,%," (vertexNormal.x as integer) \
(vertexNormal.y as integer) (vertexNormal.z as integer) ...

but will lose the precision, for example this will become 0,0,0
0 Likes
Message 3 of 6

Anonymous
Not applicable
Thats normal, as all Point3 values are Floats.
You can convert them to an Integers like this:
format "%,%,%,%,%,%,%,%,%," (vertexNormal.x as integer) \
(vertexNormal.y as integer) (vertexNormal.z as integer) ...

but will lose the precision, for example this will become 0,0,0


I know about "to integer" but I have to keep the numbers as floats. I just found in the manual how max displays floats and it seems that I will just have to live with the .0 in the decimals. Anyway thanks
0 Likes
Message 4 of 6

Anonymous
Not applicable

I know about "to integer" but I have to keep the numbers as floats. I just found in the manual how max displays floats and it seems that I will just have to live with the .0 in the decimals. Anyway thanks

Then i'm a bit confusing on what you ask for... decimals is floats. Maybe you need specific culture formating where for example "0.1" become "0,1" (ie replacing dot with comma)? or maybe to become ".1", or rounding, or something else?
0 Likes
Message 5 of 6

Anonymous
Not applicable

I know about "to integer" but I have to keep the numbers as floats. I just found in the manual how max displays floats and it seems that I will just have to live with the .0 in the decimals. Anyway thanks

Then i'm a bit confusing on what you ask for... decimals is floats. Maybe you need specific culture formating where for example "0.1" become "0,1" (ie replacing dot with comma)? or maybe to become ".1", or rounding, or something else?


It is the way maxscript outputs data from my array. I am reading UVs from my object, then I split the components and only append U and V to the second array. Then when I output this array to file with format command (I use a loop so I can arrange them as I need to) max is displaying decimals on the numbers which normally don't have any, in the original array. More explanation below

Straight output of one vertex UV array just as the function gets it is and it looks like so
#(0.5, 1, 0)

My processing way. I separate 3 components and append two of them to the SECOND array and then output it, it looks like so: #(0.5, 1.0, 0.0)

So you can see that there are unnecessary decimals added to the numbers.
0 Likes
Message 6 of 6

Anonymous
Not applicable
Yeah, the display value is different from stored value.
If you like to keep displayed value as is then use "as string" conversion.
0 Likes