question

G C avatar image
0 Likes"
G C asked Joerg Vogel answered

Numbers bring rounded in custom code

When I use the following code below, I get errors when the "processingTime" label is a decimal.

When I run the model and look at the cycle time variable it seems to round up the decimal point. I don't understand why.

FlexSim 17.1.4
processorcustom codecycle timevariables
capture.png (9.0 KiB)
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Joerg Vogel avatar image
0 Likes"
Joerg Vogel answered
numtostring(num value)

is evaluated as

numtostring(num value, 0, 0)

So a floating value is converted to a string without a defined minimum length of characters and without any characters of a possible decimal part of the number. If you want to get a desired conversions you have to compute and convert the num value before you parse the num value into the command numtostring. Otherwise the command rounds the value as the Flexsim engine always rounds number values.

5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Sebastian Hemmann avatar image
1 Like"
Sebastian Hemmann answered

For me it works if I add the precision in the numtostring command.

string timeStr = numtostring(time,0,2);

but it seems that this is not the best way to set the processtime/ cycletime of the processor. In my example there is a gap between Setting the value and the cycletime the processor takes!

Maybe you should try to add this Code to the Processor, or set a Label and just reference this.

5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.