JM°-Classic / Atomic types / Dec (Decimal)


Dec (Decimal)

For decimal numbers (with comma) we use the type "Dec", which corresponds to the Java type "double".

Alternativ existiert noch "Float".

Create

A "Dec" object is created directly with the number:

12.345

Important:
Here a point and no comma is used!

Optionally, a 'd' can be appended to the number:

123.45d
123d

Normalization

The Java type "double" occasionally leads to fractals, which can have some unpleasant effects.

If in Java e.g. 1/3 is calculated, then one receives 0.3333333333333... to infinity.
If one takes this result however again *3, then one receives again 1.

In this case, the behavior is understandable. However, the calculation of

362.2 - 362.6

to the following result:

-0.4000000000000341

JM° therefore normalizes all numbers of type "Dec".

( 362.2 - 362.6 ).print	# -0.4
( 1 / 3 ).print			# 0.333333333333
( 1 / 3 * 3 ).print		# 0.999999999999

If you don't want this normalization, you can disable it as follows (at the beginning of the script):

>openDec


- Powered by OghsWiki -

 

 

Sponsor

The development of "JayMo" is currently only possible through personal initiative.

Received:  0 €