|
Post by johnking on Dec 7, 2020 15:33:30 GMT -5
I read a string with measurement values via the serial port. The value in the string is in scientific format. Therefor I convert it to a decimal value using code below. For positive numbers it is ok. For negative numbers an % is printed before the - sign. Question: how to get of the % in the negative value ?
Code below shows the issue.
mean$ = "0.123456789e-3" ''string with positive value, ''in real world it is read via serial port from an external instrument
mean = VAL(mean$) ''convert string to number
mean$ = using("#.#######", mean) ''formats numericExpression as a string
PRINT mean$ ''prints the positive value
mean$ = "-0.123456789e-3" ''same string but now with negative value
mean = VAL(mean$) ''convert string to number
mean$ = using("#.#######", mean) ''formats numericExpression as a string
PRINT mean$ ''prints the negative value, but with an extra %
|
|
|
Post by pierre on Dec 7, 2020 16:13:09 GMT -5
I don't know why the % sign shows up before the negative value, but you can get rid of it by adding the following line
mean$ = RIGHT$(mean$, len(mean$)-1)
just before the second 'PRINT mean$' statement.
pierre
|
|
|
Post by tenochtitlanuk on Dec 7, 2020 16:57:47 GMT -5
It indicates you need to allocate TWO character positions before the decimal point, so change to
mean$ = using("##.#######", mean)
|
|
|
Post by Carl Gundel on Dec 7, 2020 18:12:27 GMT -5
It indicates you need to allocate TWO character positions before the decimal point, so change to mean$ = using("##.#######", mean) It's an overflow indicator, and it is borrowed from Microsoft BASIC's PRINT USING statement.
|
|
|
Post by johnking on Dec 9, 2020 11:48:43 GMT -5
excellent Carl, thank you. Sometimes you can search for hours, while the solution turns out simple.
|
|
|
Post by tsh73 on Dec 9, 2020 12:29:44 GMT -5
just ASK
|
|