DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Str() Function Problem

We are using DIAdem 9.1 and have experienced a problem with the Str function. We want to display values in exponential notation with four significant figures, and have the least significant digit rounded. Per my understanding of the documentation, Str() should do this. Please consider the following:

1) msgbox Str(12.6857, ".dddde")
2) msgbox Str(12.6867, ".dddde")
3) msgbox Str(12.6877, ".dddde")
4) msgbox Str(12.6887, ".dddde")
5) msgbox Str(12.6897, ".dddde")

For 1-4 DIAdem reports 1.268E+01
For 5 it reports 1.269E+01

Can someone comment on why all five are not the latter?

Thank you very much.
0 Kudos
Message 1 of 4
(3,769 Views)
I don't know why the str-function use it's own rules for rounding, but I can give you a workaround:

msgbox str(round(12.6877,trunc(log(12.6877))), ".dddde")

Repost your question if you expect a comment of NI.

Martin Bohm
bohm@a3m.com
0 Kudos
Message 2 of 4
(3,769 Views)
Hi DIAdemon,

Sorry, but you found a bug which should be fixed latest in the next main release. I've created a small function which is usable as workaround.

function myEStrFormat(dVal, sFormat)
Dim sNum, iExp
sNum = str(dVal, "d.ddddddddddddddde")
iExp = Right(sNum, len(sNum)-instr(sNum, "E")+1)
sNum = Left(sNum, instr(sNum, "E")-1)
sNum = str(val(sNum), sFormat)
myEStrFormat = sNum & "<>" & iExp
end function

dVal is the value like 12.345678
sFormat is the format like "d.dddd" (without e)
Example:
sNewVal = myEStrFormat(12.345678, "d.dddd")

Than sNewVal is 1.2346E+1

I hope this will help you and greetings

Walter
0 Kudos
Message 3 of 4
(3,768 Views)
I'm not shure whether your algorithem is working fine.
The formating of the following values will return wrong strings:

14.56789
1004.56789
1004567.89

Greetings

Walter Rick
0 Kudos
Message 4 of 4
(3,768 Views)