If I define a couple of constants, #scale=#width/1.9 that is fine and allowed, but if I definitely want that constant to be an integer, then I don't seem to be allowed to round the value or set it as a variable that was rounded. Int() doesn't seem to be allowed on constants either.
What options do I have?
How to round/convert a constant to integer?
Re: How to round/convert a constant to integer?
My idea, untested, is to scale calculation up to use only integers and then scale it back down.
Code: Select all
scale=((#width * 100) / 190) / 100Re: How to round/convert a constant to integer?
I'm confused - the code below works fine. Is this what you're trying to do or did I misunderstand?
Code: Select all
#width = 800
#scale=#width/1.9
Debug #scale ; prints "421.0526315789474"
Debug Int(#scale) ; prints "421"
var = Int(#scale)
Debug var ; prints "421"Re: How to round/convert a constant to integer?
Code: Select all
#width = 800
#scale = #width * 10/19
Debug #width
Debug #scalePB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
-
DarkDragon
- Addict

- Posts: 2347
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Re: How to round/convert a constant to integer?
OP never restricted the data type of width to integer though.
bye,
Daniel
Daniel
Re: How to round/convert a constant to integer?
Does it matter?OP never restricted the data type of width to integer though.
Code: Select all
#width = 832.9
#scale=#width/1.9
Debug #width ; prints "832.89999999999998"
Debug #scale ; prints "438.36842105263156"
Debug Int(#scale) ; prints "438"
var = Int(#scale)
Debug var ; prints "438"
-
DarkDragon
- Addict

- Posts: 2347
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Re: How to round/convert a constant to integer?
Yes, he wants to define the constant depending on another constant and the result should be integer. OP doesn't want to use Int(#scale) everywhere, it could be easily forgotten to call Int(), the constant itself is required to contain the integer value to make it less error prone.ebs wrote: Fri Jul 26, 2024 3:41 pmDoes it matter?OP never restricted the data type of width to integer though.
bye,
Daniel
Daniel
