Author Topic: Formatted a floating-point  (Read 502 times)

bavariaSHAPE

  • Newbie
  • *
  • Posts: 2
    • Office for rapid prototyping and manufacturing
Formatted a floating-point
« on: November 11, 2015, 07:58:46 AM »
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

  • Kindly Curmudgeon
  • Administrator
  • *****
  • Posts: 4191
Re: Formatted a floating-point
« Reply #1 on: November 11, 2015, 08:59:23 AM »
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

  • Newbie
  • *
  • Posts: 2
    • Office for rapid prototyping and manufacturing
Re: Formatted a floating-point
« Reply #2 on: November 12, 2015, 12:04:03 AM »
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