Hi,
When I use the expressioin of [Tools.ToInt(IPNumericUpDown1.Value*10).ToString("X4")] within control panel. I expected it works for both positive and negative numbers.
E.g. +1.5, it gave 000F, very good, no problem.
But when it came to negative numer, namely -1.5, it gave FFFFFFF1, eight characters instead of 4 that was explicitly required in the expression.
Could you help to confirm on this?
If this is really a bug, how can I work around it?
Thanks.
ToString function bug?
Howdy,
MegunoLink is built on C# and we are using that for formatting. In C# the width specifier sets the minimum width of the output. The output will expand to whatever is necessary to correctly represent the value. And an int is a 32 bit number so negative values will take 8 characters.
To solve this you can cast the integer to a 16 bit integer:
[((Int16)Tools.ToInt(n.Value*10)).ToString("X4")]
Hope this helps,
Paul.
MegunoLink is built on C# and we are using that for formatting. In C# the width specifier sets the minimum width of the output. The output will expand to whatever is necessary to correctly represent the value. And an int is a 32 bit number so negative values will take 8 characters.
To solve this you can cast the integer to a 16 bit integer:
[((Int16)Tools.ToInt(n.Value*10)).ToString("X4")]
Hope this helps,
Paul.