We value your input!
Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey

Libraries & objects
About Archicad and BIMcloud libraries, their management and migration, objects and other library parts, etc.

Extra accuracy STR{2}

Anonymous
Not applicable
Hello!
I need to mathimatic rounding:
0.0245 -> 0.03

But in this code

value = 0.0245
string_result = STR("%.2", value)

i have
0.02

May be i need to use STR{2} with extra accuracy flags...
But in documentation of GDL no examples ((

Please, help me!)
2 REPLIES 2
Anonymous
Not applicable
Tsepov wrote:
Hello!
I need to mathimatic rounding:
0.0245 -> 0.03

But in this code

value = 0.0245
string_result = STR("%.2", value)

i have
0.02

May be i need to use STR{2} with extra accuracy flags...
But in documentation of GDL no examples ((

Please, help me!)
2.4xxx will mathematically round to 2.0
The rounding point is 0.5

If you add something to it then it will round, but no program i know will round a 0.4 to the next hole number...

With crazy clients who wanted custom rounding, we built rounding factors that we added to numbers to get the desired result, i.e. you could add 0.005 to your 0.0245 to give you a roundable number
therfore
a 0.02450001 that displays 0.025 at 3DPs and displays as 0.02 at 2DPs

becomes 0.02500001 that displays as 0.025 at 3DPs and displays as 0.03 at 2DPs

it depends on the level of accuracy that you work in...
runxel
Legend
I suppose you don't actually want to "round" something, but to make it always bigger. This is called ceiling.
There is indeed a function called "CEIL" in GDL, but the result will be of course Integer, not Float:
c = CEIL(-2.25 )   ! =-2

w = 25.276
w = CEIL(w)        ! w=26
So if you want it to remain Float you need to e.g.
con = 100

n = 0.0245
n * con    ! n=2.45

n = CEIL(n)     ! n=3

n = n / con     ! n=0.03
Lucas Becker | AC 27 on Mac | Graphisoft Insider Panelist | Author of Runxel's Archicad Wiki | Editor at SelfGDL | Developer of the GDL plugin for Sublime Text | My List of AC shortcomings & bugs | I Will Piledrive You If You Mention AI Again |

POSIWID – The Purpose Of a System Is What It Does /// «Furthermore, I consider that Carth... yearly releases must be destroyed»

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!