DesignCAD 3D Max 2027 box
Now available

DesignCAD 2027

Hatches that follow their boundaries, an on-screen dial to turn your model, and a way to find any command by name, in a clean Windows 11 look.

Formatted a floating-point

Started by bavariaSHAPE, November 11, 2015, 07:58:46 AM

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

bavariaSHAPE

I'm doing my first steps with BasicCAD. And now I have the first question.

How can I remove the decimal places? I leave the result in the window to show, for example, 125,000. But I would like the result 125 is there.
How does it work? In addition, the result is in a variable.

Example:

     fa = ROUND(w / sal)

     MESSAGE "Facettenanzahl: ", fa

fa should be 125 and not 125 000

Many thanks for the help.

Achom

DrollTroll

DesignCAD uses floating point values for all numbers. When displayed in a dialog box or printed to a string they are usually formatted to the current PRECISION setting.

If you set PRECISION 0 before showing the number, it should show with zero decimal places. Later if you need to format it to 3 places, for example, use PRECISION 3 before displaying the value.

Alternatively, you can use the FORMAT statement to format floating point numbers to a string in a variety of formats.

Example:
x = 3.14159
fmt$ = "Small PI: %.2f"
FORMAT out$, fmt$, x
MESSAGE out$

You should get the result "Small PI: 3.14". If you are at all familiar with C/C++'s printf function, you should grasp the concept. See the documentation on FORMAT for more information.
25 years with DesignCAD

bavariaSHAPE

Many thanks DrollTroll,

your examples have helped me a lot. I am not a programmer, so I am not familiar with C/C ++. Nevertheless, I want to make my life easier with different macros. And it makes a lot of fun when it works.

Until next time, if I have a problem again.

Best regards.

Achim