VB.NET串联错误 [英] VB.NET concatenation error

查看:63
本文介绍了VB.NET串联错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这行代码想要连接-或至少解决了循环问题...

I have this line of code which I want to concatenate -or at least solve the loop problem...

test = 1 - ("0." & thisnumber(0) & thisnumber(1) & thisnumber(2))

我希望它有一个循环...

I want this to have a loop in it...

-增加thisnumber()

-Increasing thisnumber()

直到大约500,

有人可以在其中实现循环吗?

Can some implement a loop into this?

或提出一种方法...

Or suggest a way...

非常感谢..

詹姆斯:)

因此,如果我的值thisnumber(0)= 1,thisnumber(1)= 5,thisnumber(2)= 0,thisnumber(3)= 7 ...,它的取值范围为1-0.1507 ...(但我想要一个循环,这样就不需要我全部输入就可以完成全部500个)-我想要1,000,000个,所以这将是一个很大的问题.

So if I had values thisnumber(0) = 1, thisnumber(1) = 5, thisnumber(2) = 0, thisnumber(3) = 7... It would do 1 - 0.1507... (But I want a loop so it does all 500 without me typing them all out) -I'm wanting 1,000,000 so it would be a huge problem.

推荐答案

类似的事情,也许...(对不起,我的VB语法已经有一段时间了)

Something like this, maybe... (Excuse my VB syntax, it's been a while)

dim num as double = 0.0

for i as integer = 0 to 500
    num += thisnumber(i) / (10 ^ (i + 1))
next 

test = 1 - num

但是...这将在您达到500位之前溢出,而我仍然想知道为什么您的输入首先是这种格式的...

However... this will overflow way before you get to 500 digits, and I still have to wonder why your input is in this format in the first place...

:基于OP的评论,这是减去溢出的版本...

based on the OP's comments, here's a version minus overflow...

dim num as double = 0.0
dim factor as double = 1.0;

for i as integer = 0 to 500
    factor /= 10
    num += thisnumber(i) * factor
next 

test = 1 - num

此版本不会溢出,但在此过程中会遇到十进制精度问题.如果正如OP所建议的那样,这是关于高精度找到Pi的话,也许有更好的方法-但是在不知道实际问题的情况下,我不确定是否值得详细介绍.

This version won't overflow, but you'll run into decimal precision issues along the way. If, as the OP suggests, this is about finding Pi to high accuracy, there are probably better ways - but without knowing the actual problem, I'm not sure it's worth going into detail.

这篇关于VB.NET串联错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆