<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://coderwiki.org/index.php?action=history&amp;feed=atom&amp;title=Casting</id>
	<title>Casting - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://coderwiki.org/index.php?action=history&amp;feed=atom&amp;title=Casting"/>
	<link rel="alternate" type="text/html" href="http://coderwiki.org/index.php?title=Casting&amp;action=history"/>
	<updated>2026-05-19T03:47:55Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>http://coderwiki.org/index.php?title=Casting&amp;diff=69&amp;oldid=prev</id>
		<title>Dylan: new</title>
		<link rel="alternate" type="text/html" href="http://coderwiki.org/index.php?title=Casting&amp;diff=69&amp;oldid=prev"/>
		<updated>2025-08-11T12:09:22Z</updated>

		<summary type="html">&lt;p&gt;new&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;#039;&amp;#039;&amp;#039;Casting&amp;#039;&amp;#039;&amp;#039; in programming is the process of converting a [[value]] (often stored in a [[variable]]) from one [[data type]] to another.&lt;br /&gt;
&lt;br /&gt;
This changes what [[Method|methods]] we can call on the [[value]].&lt;br /&gt;
&lt;br /&gt;
== Syntax ==&lt;br /&gt;
The [[syntax]] to cast a [[value]] varies a lot by the [[programming language]].&lt;br /&gt;
&lt;br /&gt;
C-style casting is done like this:&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
(type)value&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;For example, to cast an integer to a float, we would do:&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot; line=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
int number = 4;&lt;br /&gt;
float fnumber = (float)4;&lt;br /&gt;
printf(&amp;quot;%f&amp;quot;, fnumber); // 4.0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Lossy type conversion ==&lt;br /&gt;
Sometimes, while a [[value]] could fit in the [[source]] data type, it can&amp;#039;t properly fit into the [[target]] data type. For example, a decimal [[Floating point|float]] into an [[integer]].&lt;br /&gt;
&lt;br /&gt;
In this case, the program may either return an [[error]], throw an [[exception]], or the value may be [[Rounding|rounded]] or [[Truncation|truncated]]. In the case of casting an [[integer]] into a [[floating point]] number, the value is [[Truncation|truncated]]:&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot; line=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
float f = 3.14;&lt;br /&gt;
int i = (float)f;&lt;br /&gt;
printf(&amp;quot;%d&amp;quot;, i); // 3&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Dylan</name></author>
	</entry>
</feed>