15.04.2018 Views

programming-for-dummies

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

180<br />

Converting Data Types<br />

to a Single data type can you store the value into the AverageAge variable,<br />

which can hold only a Single data type.<br />

When you convert data types, you may lose some precision in your numbers.<br />

For example, converting an Integer data type (such as 67) to a<br />

Single data type means converting the number 67 to 67.0. But what if you<br />

convert a Single data type (such as 3.14) to an Integer data type? Then<br />

the computer rounds the value to the nearest whole number, so the number<br />

3.14 gets converted into 3. What happened to the 0.14? The computer throws<br />

it away. So when converting between data types, make sure you can af<strong>for</strong>d to<br />

lose any precision in your numbers or else your program may wind up using<br />

inexact values, which could wreck the accuracy of your calculations.<br />

No matter what type of data you have, every <strong>programming</strong> language allows<br />

multiple ways to manipulate that data. The way you combine operators and<br />

functions determines what your program actually does.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!