
assigning specific number of significant figures

I was writing a user defined function and noticed my input numbers get truncated.
Function freq(num)
Variable num
print num
String numst = num2str(num)
print numst
end
freq(32750.25)
The first truncation occurs in the first line (variable num). The second truncation is when it gets converted to string.
So freq(32750.25) outputs 32750.2 and 32750 sequentially.
Is there a way I can keep the input number intact all the way?
My goal isnt just to print the numbers without getting them truncated. I need to be able to save the number in its entirety.
I found this below on this forum but for some reason when I run it, I get a function compilation error, saying "unknown/inappropriate name or symbol."
Function/S Num2StrF(num,pad)
variable num, pad
string fstr
sprintf fstr, "%.*f", pad,num
print fstr
return fstr
end
If I just comment out the "return fstr" line, it does print fstr to the precision I desire
The number (value) isn't truncated at all, it is just that the default print format is "%g", which is the same %g used in the C library, about 6 significant digits.
The actual value is a double-precision IEEE floating point number, accurate to 53 bits or about 16 decimal digits.
Use Print/D for more precision.
A good test is a number that has a lot of digits, like our good friend pi:
September 19, 2018 at 10:21 am - Permalink