vpa adding ".0" to the end

2 次查看(过去 30 天)
So I am needing to use vpa(#,d) for a very large number on the magnitude of 1x10^(250). I've figured out how to use it but for some reason it adds .0 to the end which I can't have.
example:
n = vpa('3546',32)
disp(n)
output:
3546.0
The reason I can't have the .0 is because I am constructing a sequence that depends on if there are any 0s in the number and the ".0" at the end makes it think it always has a 0 in the number
N = string(n);
strlength(N)
N = convertStringsToChars(N);
for i = 1:strlength(N)
if N(i) == '0' || N(i) == '1' || N(i) == '5'
disp('N(i) = 0,1,5')
skpchk = 'True';
break;
end
end

采纳的回答

Walter Roberson
Walter Roberson 2019-11-14
https://www.mathworks.com/help/matlab/matlab_prog/searching-and-replacing.html
regexprep can also be used.
I can also offer you code for r2019a and later that converts all floating point software numbers into rationals. In the case of integers with .0 that would construct the integers. However there is the issue that vpa shows you a truncated value that is not necessarily exactly what is stored, so if the numbers do not convert exactly to integers then they might not come out as expected. But the code could easily be adapted to round before converting to rational.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by