# Chapter 2, About Type conversion, what happening?

**URL:** <https://forums.kodeco.com/t/chapter-2-about-type-conversion-what-happening/39096>\
**Category:** Swift Apprentice\
**Created:** [February 2, 2018, 3:46am UTC](https://forums.kodeco.com/t/chapter-2-about-type-conversion-what-happening/39096 "2018-02-02T03:46:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tom16](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@tom16](https://forums.kodeco.com/u/tom16)\
**Post date:** [February 2, 2018, 3:46am UTC](https://forums.kodeco.com/t/chapter-2-about-type-conversion-what-happening/39096/1 "2018-02-02T03:46:33Z")

</div>

var integer: Int = 100  
var decimal: Double = 12.5  
integer = Int(decimal)  
I just wonder to know that which method to call!  
how it happened internal call to change type conversion?  
//integer = Int(exactly: \<#T##Double#\>)  
//integer = Int(\<#T##source: Double##Double#\>)  
//integer = struct Int : FixedWidthInteger, SignedInteger

---

<div class="post-metadata">

**Author:** ![jayantvarma](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jayantvarma/32/111768_2.png) [@jayantvarma](https://forums.kodeco.com/u/jayantvarma)\
**Post date:** [February 2, 2018, 1:59pm UTC](https://forums.kodeco.com/t/chapter-2-about-type-conversion-what-happening/39096/2 "2018-02-02T13:59:49Z")

</div>

Hi @tom16,  
what is it that you want to exactly do? When you are trying to instantiate an Int from a Double as in your example of 12.5, what do you want it to be? 12 or 13?

If you instantiate it as an Int, it will give you the value of 12, however if your round it, it will give you the value of 13 which will still remain a Double.

```
let decimal = 12.5
let int1 = Int(decimal)
let int2 = Int(decimal.rounded())
print(int1, int2) // 12 13

```

cheers,

Jayant

---

<div class="post-metadata">

**Author:** ![tom16](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@tom16](https://forums.kodeco.com/u/tom16)\
**Post date:** [February 2, 2018, 2:35pm UTC](https://forums.kodeco.com/t/chapter-2-about-type-conversion-what-happening/39096/3 "2018-02-02T14:35:25Z")

</div>

thank you very much, I also wonder to know in Int struct , which method to call in default ?

---

<div class="post-metadata">

**Author:** ![jayantvarma](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jayantvarma/32/111768_2.png) [@jayantvarma](https://forums.kodeco.com/u/jayantvarma)\
**Post date:** [February 2, 2018, 2:45pm UTC](https://forums.kodeco.com/t/chapter-2-about-type-conversion-what-happening/39096/4 "2018-02-02T14:45:01Z")

</div>

Hi @tom16,  
You should use the `Int(number)` function, while you can see the other options, they are not really something that you can choose. They are convenience initialisers for different type of data types. You can intitialize an Int from a CGFloat, Float, Float80, Double, NSNumber.

So in my opinion, to keep things simple, simply initialise or convert a floating point/decimal number to an Int simply by using `Int(number)`

You can know more about the int structure form the Apple Documenation page on Int which is found at [Apple Developer Documentation](https://developer.apple.com/documentation/swift/int)

cheers,

Jayant

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [July 18, 2018, 7:50pm UTC](https://forums.kodeco.com/t/chapter-2-about-type-conversion-what-happening/39096/5 "2018-07-18T19:50:17Z")

</div>

Closed on July 18, 2018, 7:50pm UTC

This topic was automatically closed after 166 days. New replies are no longer allowed.
