I just want to float to the dining hall after-- " so much easier, so much less painful."
我只想下午时飘去餐厅-,更加容易,更少痛苦“
As you walk amid the buildings and trees, as you see your friends and classmates, allow these emotions to float through you, freely, lightly.
在你走在建筑物和树木之间时,在你看到朋友和同学时,让那些情绪流遍你的全身,自由地,轻盈地。
And as you might expect, I'm going to then try and see if I can convert that into a float.
正如你希望的我要试着把他们转化为浮点数,等一等。
So what that means is the compiler is actually going to first "cast" so to speak 13 from whatever it is - to a float -- to a floating point value -- and then perform the division for us.
所以这里的意思是编译器将,做“计算“,譬如13这样一个浮点数,-到另一个浮点数-,然后为我们处理除法。
Whatever they are, whatever it is that your feeling, allow it to float through you. Naturally.
不论是怎样的情绪,不论感觉到什么,让它流过你的全身,自然地。
I just want to float to Sanders in the morning.
我只想早上时飘去剧院。
OK, says it says enter a float. I give it something that can be converted into a float, it says fine. I'm going to go back and run it again though. If I run it again, it says enter a float.
好了,看到他说输入一个浮点数,我输入它可以转换为浮点数的值,那没问题,我回过来再运行一遍,如果我再运行一遍。
And that then let's me get to, basically, base this code. Having done that, height I simply call base with get float, I call height with get float, and do the rest of the work.
现在让我们看看这段代码,其实已经写好了,我简单的调用下,用来得到一个浮点数,再调用下,来得到另外一个浮点数,然后做剩下的工作就可以了。
I can't rely on the user. I want to make sure I get a float in it, so how do I do that?
我想确保这儿我得到的是一个浮点数,我该怎么做呢?
Now, this is not the nicest way to do it but it'll work. I can look at the type of the value of base and compare it to the type of an actual float and see, are they the same?
这不是最好的办法但它确实有用,我可以得到底的值的类型然后,和一个真的浮点数的类型比比,看他们是不是一样?
That's going to give me a float.
那将会给我们一个浮点数。
So yes, f is a float, but that solution is too late; we need to fix the problem sooner.
是的,f是一个浮点数,但是那个解决方案太迟了;,我们应该在次之前把问题解决。
If we did that, if we moved f minus 32 over to the left, that would give me a floating point answer because f is a float.
如果你那样做,如果我们把,放前面,那将会给我们一个浮点数答案,因为f是浮点数。
I need to have a float. I need to have another float here, it's giving me some information.
这儿还需要一个,它给了我这样的信息。
Need to get the base in. Second thing I want to do, I need to get the height, so I'm going to input a value for the height, also as a float, a floating point.
也就是输入底的值,第二件我想要做的,事情就是得到三角形的高,因此我会输入一个值作为三角形的高,同样也是一个浮点数。
If I wanted to get full, real division, I should make one of them a float.
如果我想要得到真正的除法答案,我需要把他们之中的一个,变为浮点数类型。
It means anybody using that little function get float doesn't have to worry about what's inside of it. So for example, I decide I want to change the message I print out, I don't have to change the function, I just pass in a different parameter.
这代表着用这个方法去获得浮点数,的任何人都不用担心具体的实现了,例如,如果我想改变下,显示的信息的话,我不必去改变方法,我传个不同的参数就可以了。
So if I were to solve this problem, here's the way I would do it. I would say, first thing I want to do, is I want to input a value for the base as a float.
如果我想要解决这个问题,这就是我要解决它的方式了,第一件我要做的事情就是要,输入一个浮点数作为三角形的底。
So it turns out there's a solution to this: If you need more precision, more digits after the decimal point than a float allows, what do you go for instead?
所以这里有一个解决方案:,如果你需要比float类型允许的更高精度,小数点后更多位数,那你该用什么取代它?
> David: At some point in time, I'm going to have to have declared the variable as a float before I can then hand it to printf as the insertion value for that format strength.
>,大卫:在一个特定的时间,我将需要,声明float类型这样的变量,那样我就可以把它打印出来,像是格式化优点的插入值。
I can't rely on Professor Guttag if I give this- if this code to him, I can't rely on him to type in a float. Actually I can, because he's a smart guy, but in general, I can't rely on the user-- I wouldn't do it right to see if you did.
当Guttag使用这段代码的时候-,我不能相信他一定会输入一个浮点数,实际上我能因为他很聪明,但是总体上来讲,别相信用户一定会按照规则来-,我会故意做错来试试你的程序的。
I if I go over here, and I say float of three, it's going to do the conversion.
用float来处理3,它将能完成装换,但是如果我吧这个转化为浮点数。
Now if you look at that list, there is actually something I didn't seem to check, which is, I said I wanted a float stored in hyp.
看下上面的清单,实际上我还有一些东西忘了检查,也就是说hyp中存储的,应该是浮点数类型。
I need to now put this float somewhere, and I'll put it in a variable called f that you can call it whatever you'd like.
我现在需要把这个浮点数放在哪个地方,然后我把它放在,一个叫做f的变量里,你也可以给这个变量取其它的你喜欢的名字。
应用推荐