Saving decimal values in array elements as characters
Nicopowers
Posts: 12
Hi everybody,
I am having difficulties formatting data to be transferred over ZigBee API communication using 64-bit addressing. Let's assume that I want to transfer the decimal value 41,410 through an API method that takes string values as its input. So, let's say:
How would I save each individual digit of my decimal variable to one element of "my_buffer" array to achieve the following?:
We need to make it work for any decimal value , I would really appreciate your help.
Thank you!
I am having difficulties formatting data to be transferred over ZigBee API communication using 64-bit addressing. Let's assume that I want to transfer the decimal value 41,410 through an API method that takes string values as its input. So, let's say:
VAR byte my_buffer[100] PUB Main | my_value my_value := 41410
How would I save each individual digit of my decimal variable to one element of "my_buffer" array to achieve the following?:
my_buffer[0] := "4" my_buffer[1] := "1" my_buffer[2] := "4" my_buffer[3] := "1" my_buffer[4] := "0" ' The values need to be saved as a string
We need to make it work for any decimal value , I would really appreciate your help.
Thank you!
Comments
This object includes a ".dec" method like Mike Green suggested but this method lets you specify where to have the characters stored.
Using your example, you'd use the following code:
Of course this assumes you're using "Format" to identify the "strfmt.spin" object.