[{"data":1,"prerenderedAt":1441},["ShallowReactive",2],{"doc-\u002Fglossary\u002Fwhat-is-a-float-in-python":3},{"id":4,"title":5,"body":6,"description":1434,"extension":1435,"meta":1436,"navigation":403,"path":1437,"seo":1438,"stem":1439,"__hash__":1440},"content\u002Fglossary\u002Fwhat-is-a-float-in-python.md","What Is a Float in Python?",{"type":7,"value":8,"toc":1416},"minimark",[9,13,35,38,44,49,54,57,78,84,92,96,99,102,119,122,125,187,190,222,232,280,282,330,334,337,354,357,441,443,463,466,474,481,485,491,508,513,530,533,548,550,599,601,640,649,652,698,700,724,728,731,775,777,801,804,826,830,833,836,838,859,861,870,877,880,909,911,920,930,934,943,945,985,987,1001,1004,1071,1073,1097,1103,1123,1126,1156,1168,1172,1175,1198,1201,1288,1291,1302,1306,1311,1325,1329,1336,1340,1348,1352,1355,1359,1368,1372,1412],[10,11,5],"h1",{"id":12},"what-is-a-float-in-python",[14,15,16,17,21,22,26,27,30,31,34],"p",{},"A ",[18,19,20],"strong",{},"float"," in Python is a number that can include a decimal point. Beginners often use floats for values like ",[23,24,25],"code",{},"3.14",", ",[23,28,29],{},"2.5",", or ",[23,32,33],{},"-0.75",".",[14,36,37],{},"Floats are useful when you need numbers that are not just whole numbers. For example, you might use them for measurements, prices in simple examples, or division results.",[14,39,40,41,43],{},"This page explains what the term ",[18,42,20],{}," means, how it looks in Python, and how it differs from an integer.",[45,46,48],"h2",{"id":47},"definition","Definition",[14,50,16,51,53],{},[18,52,20],{}," is a numeric type in Python used for numbers with decimal values.",[14,55,56],{},"Examples:",[58,59,60,65,69,73],"ul",{},[61,62,63],"li",{},[23,64,25],{},[61,66,67],{},[23,68,29],{},[61,70,71],{},[23,72,33],{},[61,74,75],{},[23,76,77],{},"5.0",[14,79,80,81,83],{},"Even though ",[23,82,77],{}," looks like a whole number, Python still treats it as a float because it has a decimal point.",[14,85,86,87,34],{},"If you want to compare floats with whole numbers, see ",[88,89,91],"a",{"href":90},"\u002Fglossary\u002Fwhat-is-an-integer-in-python\u002F","what is an integer in Python",[45,93,95],{"id":94},"how-floats-look-in-python","How floats look in Python",[14,97,98],{},"Floats usually appear with a decimal point.",[14,100,101],{},"Common examples:",[58,103,104,109,114],{},[61,105,106],{},[23,107,108],{},"1.5",[61,110,111],{},[23,112,113],{},"0.0",[61,115,116],{},[23,117,118],{},"-3.2",[14,120,121],{},"A decimal point usually means the value is a float.",[14,123,124],{},"Python also supports scientific notation. This also creates a float:",[126,127,132],"pre",{"className":128,"code":129,"language":130,"meta":131,"style":131},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","x = 1e3\nprint(x)\nprint(type(x))\n","python","",[23,133,134,151,169],{"__ignoreMap":131},[135,136,139,143,147],"span",{"class":137,"line":138},"line",1,[135,140,142],{"class":141},"su5hD","x ",[135,144,146],{"class":145},"smGrS","=",[135,148,150],{"class":149},"srdBf"," 1e3\n",[135,152,154,158,162,166],{"class":137,"line":153},2,[135,155,157],{"class":156},"sptTA","print",[135,159,161],{"class":160},"sP7_E","(",[135,163,165],{"class":164},"slqww","x",[135,167,168],{"class":160},")\n",[135,170,172,174,176,180,182,184],{"class":137,"line":171},3,[135,173,157],{"class":156},[135,175,161],{"class":160},[135,177,179],{"class":178},"sZMiF","type",[135,181,161],{"class":160},[135,183,165],{"class":164},[135,185,186],{"class":160},"))\n",[14,188,189],{},"Output:",[126,191,193],{"className":128,"code":192,"language":130,"meta":131,"style":131},"1000.0\n\u003Cclass 'float'>\n",[23,194,195,200],{"__ignoreMap":131},[135,196,197],{"class":137,"line":138},[135,198,199],{"class":149},"1000.0\n",[135,201,202,205,209,213,216,219],{"class":137,"line":153},[135,203,204],{"class":145},"\u003C",[135,206,208],{"class":207},"sbsja","class",[135,210,212],{"class":211},"sjJ54"," '",[135,214,20],{"class":215},"s_sjI",[135,217,218],{"class":211},"'",[135,220,221],{"class":145},">\n",[14,223,224,225,231],{},"You can check a value's type with ",[88,226,228],{"href":227},"\u002Freference\u002Fpython-type-function-explained\u002F",[23,229,230],{},"type()",":",[126,233,235],{"className":128,"code":234,"language":130,"meta":131,"style":131},"print(type(3.14))\nprint(type(5.0))\nprint(type(5))\n",[23,236,237,251,265],{"__ignoreMap":131},[135,238,239,241,243,245,247,249],{"class":137,"line":138},[135,240,157],{"class":156},[135,242,161],{"class":160},[135,244,179],{"class":178},[135,246,161],{"class":160},[135,248,25],{"class":149},[135,250,186],{"class":160},[135,252,253,255,257,259,261,263],{"class":137,"line":153},[135,254,157],{"class":156},[135,256,161],{"class":160},[135,258,179],{"class":178},[135,260,161],{"class":160},[135,262,77],{"class":149},[135,264,186],{"class":160},[135,266,267,269,271,273,275,278],{"class":137,"line":171},[135,268,157],{"class":156},[135,270,161],{"class":160},[135,272,179],{"class":178},[135,274,161],{"class":160},[135,276,277],{"class":149},"5",[135,279,186],{"class":160},[14,281,189],{},[126,283,285],{"className":128,"code":284,"language":130,"meta":131,"style":131},"\u003Cclass 'float'>\n\u003Cclass 'float'>\n\u003Cclass 'int'>\n",[23,286,287,301,315],{"__ignoreMap":131},[135,288,289,291,293,295,297,299],{"class":137,"line":138},[135,290,204],{"class":145},[135,292,208],{"class":207},[135,294,212],{"class":211},[135,296,20],{"class":215},[135,298,218],{"class":211},[135,300,221],{"class":145},[135,302,303,305,307,309,311,313],{"class":137,"line":153},[135,304,204],{"class":145},[135,306,208],{"class":207},[135,308,212],{"class":211},[135,310,20],{"class":215},[135,312,218],{"class":211},[135,314,221],{"class":145},[135,316,317,319,321,323,326,328],{"class":137,"line":171},[135,318,204],{"class":145},[135,320,208],{"class":207},[135,322,212],{"class":211},[135,324,325],{"class":215},"int",[135,327,218],{"class":211},[135,329,221],{"class":145},[45,331,333],{"id":332},"when-beginners-use-floats","When beginners use floats",[14,335,336],{},"Beginners often use floats in situations like these:",[58,338,339,342,345,348],{},[61,340,341],{},"Measurements such as height, weight, or distance",[61,343,344],{},"Money examples in simple lessons",[61,346,347],{},"Division results",[61,349,350,351],{},"User input converted with ",[23,352,353],{},"float()",[14,355,356],{},"Example:",[126,358,360],{"className":128,"code":359,"language":130,"meta":131,"style":131},"height = 1.75\nprice = 4.99\nresult = 7 \u002F 2\n\nprint(height)\nprint(price)\nprint(result)\n",[23,361,362,372,382,398,405,417,429],{"__ignoreMap":131},[135,363,364,367,369],{"class":137,"line":138},[135,365,366],{"class":141},"height ",[135,368,146],{"class":145},[135,370,371],{"class":149}," 1.75\n",[135,373,374,377,379],{"class":137,"line":153},[135,375,376],{"class":141},"price ",[135,378,146],{"class":145},[135,380,381],{"class":149}," 4.99\n",[135,383,384,387,389,392,395],{"class":137,"line":171},[135,385,386],{"class":141},"result ",[135,388,146],{"class":145},[135,390,391],{"class":149}," 7",[135,393,394],{"class":145}," \u002F",[135,396,397],{"class":149}," 2\n",[135,399,401],{"class":137,"line":400},4,[135,402,404],{"emptyLinePlaceholder":403},true,"\n",[135,406,408,410,412,415],{"class":137,"line":407},5,[135,409,157],{"class":156},[135,411,161],{"class":160},[135,413,414],{"class":164},"height",[135,416,168],{"class":160},[135,418,420,422,424,427],{"class":137,"line":419},6,[135,421,157],{"class":156},[135,423,161],{"class":160},[135,425,426],{"class":164},"price",[135,428,168],{"class":160},[135,430,432,434,436,439],{"class":137,"line":431},7,[135,433,157],{"class":156},[135,435,161],{"class":160},[135,437,438],{"class":164},"result",[135,440,168],{"class":160},[14,442,189],{},[126,444,446],{"className":128,"code":445,"language":130,"meta":131,"style":131},"1.75\n4.99\n3.5\n",[23,447,448,453,458],{"__ignoreMap":131},[135,449,450],{"class":137,"line":138},[135,451,452],{"class":149},"1.75\n",[135,454,455],{"class":137,"line":153},[135,456,457],{"class":149},"4.99\n",[135,459,460],{"class":137,"line":171},[135,461,462],{"class":149},"3.5\n",[14,464,465],{},"A useful beginner rule is this:",[58,467,468],{},[61,469,470,473],{},[23,471,472],{},"\u002F"," returns a float in Python",[14,475,476,477,34],{},"If you want a wider overview of number types, see ",[88,478,480],{"href":479},"\u002Flearn\u002Fpython-numbers-explained-int-float-complex\u002F","Python numbers explained: int, float, complex",[45,482,484],{"id":483},"float-vs-int","Float vs int",[14,486,487,488,490],{},"An ",[18,489,325],{}," stores whole numbers:",[58,492,493,498,503],{},[61,494,495],{},[23,496,497],{},"1",[61,499,500],{},[23,501,502],{},"25",[61,504,505],{},[23,506,507],{},"-7",[14,509,16,510,512],{},[18,511,20],{}," stores numbers with decimal values:",[58,514,515,520,525],{},[61,516,517],{},[23,518,519],{},"1.0",[61,521,522],{},[23,523,524],{},"25.5",[61,526,527],{},[23,528,529],{},"-7.25",[14,531,532],{},"These two values are not the same type:",[58,534,535,542],{},[61,536,537,539,540],{},[23,538,277],{}," → ",[23,541,325],{},[61,543,544,539,546],{},[23,545,77],{},[23,547,20],{},[14,549,356],{},[126,551,553],{"className":128,"code":552,"language":130,"meta":131,"style":131},"print(type(5))\nprint(type(5.0))\nprint(5 == 5.0)\n",[23,554,555,569,583],{"__ignoreMap":131},[135,556,557,559,561,563,565,567],{"class":137,"line":138},[135,558,157],{"class":156},[135,560,161],{"class":160},[135,562,179],{"class":178},[135,564,161],{"class":160},[135,566,277],{"class":149},[135,568,186],{"class":160},[135,570,571,573,575,577,579,581],{"class":137,"line":153},[135,572,157],{"class":156},[135,574,161],{"class":160},[135,576,179],{"class":178},[135,578,161],{"class":160},[135,580,77],{"class":149},[135,582,186],{"class":160},[135,584,585,587,589,591,594,597],{"class":137,"line":171},[135,586,157],{"class":156},[135,588,161],{"class":160},[135,590,277],{"class":149},[135,592,593],{"class":145}," ==",[135,595,596],{"class":149}," 5.0",[135,598,168],{"class":160},[14,600,189],{},[126,602,604],{"className":128,"code":603,"language":130,"meta":131,"style":131},"\u003Cclass 'int'>\n\u003Cclass 'float'>\nTrue\n",[23,605,606,620,634],{"__ignoreMap":131},[135,607,608,610,612,614,616,618],{"class":137,"line":138},[135,609,204],{"class":145},[135,611,208],{"class":207},[135,613,212],{"class":211},[135,615,325],{"class":215},[135,617,218],{"class":211},[135,619,221],{"class":145},[135,621,622,624,626,628,630,632],{"class":137,"line":153},[135,623,204],{"class":145},[135,625,208],{"class":207},[135,627,212],{"class":211},[135,629,20],{"class":215},[135,631,218],{"class":211},[135,633,221],{"class":145},[135,635,636],{"class":137,"line":171},[135,637,639],{"class":638},"s39Yj","True\n",[14,641,642,643,645,646,648],{},"So ",[23,644,277],{}," and ",[23,647,77],{}," can be equal in value, but they are different types.",[14,650,651],{},"Python can also do math with ints and floats together:",[126,653,655],{"className":128,"code":654,"language":130,"meta":131,"style":131},"total = 2 + 3.5\nprint(total)\nprint(type(total))\n",[23,656,657,673,684],{"__ignoreMap":131},[135,658,659,662,664,667,670],{"class":137,"line":138},[135,660,661],{"class":141},"total ",[135,663,146],{"class":145},[135,665,666],{"class":149}," 2",[135,668,669],{"class":145}," +",[135,671,672],{"class":149}," 3.5\n",[135,674,675,677,679,682],{"class":137,"line":153},[135,676,157],{"class":156},[135,678,161],{"class":160},[135,680,681],{"class":164},"total",[135,683,168],{"class":160},[135,685,686,688,690,692,694,696],{"class":137,"line":171},[135,687,157],{"class":156},[135,689,161],{"class":160},[135,691,179],{"class":178},[135,693,161],{"class":160},[135,695,681],{"class":164},[135,697,186],{"class":160},[14,699,189],{},[126,701,703],{"className":128,"code":702,"language":130,"meta":131,"style":131},"5.5\n\u003Cclass 'float'>\n",[23,704,705,710],{"__ignoreMap":131},[135,706,707],{"class":137,"line":138},[135,708,709],{"class":149},"5.5\n",[135,711,712,714,716,718,720,722],{"class":137,"line":153},[135,713,204],{"class":145},[135,715,208],{"class":207},[135,717,212],{"class":211},[135,719,20],{"class":215},[135,721,218],{"class":211},[135,723,221],{"class":145},[45,725,727],{"id":726},"simple-example","Simple example",[14,729,730],{},"Here is a very small example of a float stored in a variable:",[126,732,734],{"className":128,"code":733,"language":130,"meta":131,"style":131},"temperature = 21.5\n\nprint(temperature)\nprint(type(temperature))\n",[23,735,736,746,750,761],{"__ignoreMap":131},[135,737,738,741,743],{"class":137,"line":138},[135,739,740],{"class":141},"temperature ",[135,742,146],{"class":145},[135,744,745],{"class":149}," 21.5\n",[135,747,748],{"class":137,"line":153},[135,749,404],{"emptyLinePlaceholder":403},[135,751,752,754,756,759],{"class":137,"line":171},[135,753,157],{"class":156},[135,755,161],{"class":160},[135,757,758],{"class":164},"temperature",[135,760,168],{"class":160},[135,762,763,765,767,769,771,773],{"class":137,"line":400},[135,764,157],{"class":156},[135,766,161],{"class":160},[135,768,179],{"class":178},[135,770,161],{"class":160},[135,772,758],{"class":164},[135,774,186],{"class":160},[14,776,189],{},[126,778,780],{"className":128,"code":779,"language":130,"meta":131,"style":131},"21.5\n\u003Cclass 'float'>\n",[23,781,782,787],{"__ignoreMap":131},[135,783,784],{"class":137,"line":138},[135,785,786],{"class":149},"21.5\n",[135,788,789,791,793,795,797,799],{"class":137,"line":153},[135,790,204],{"class":145},[135,792,208],{"class":207},[135,794,212],{"class":211},[135,796,20],{"class":215},[135,798,218],{"class":211},[135,800,221],{"class":145},[14,802,803],{},"What this does:",[58,805,806,812,818],{},[61,807,808,811],{},[23,809,810],{},"temperature = 21.5"," stores a float in a variable",[61,813,814,817],{},[23,815,816],{},"print(temperature)"," shows the value",[61,819,820,823,824],{},[23,821,822],{},"print(type(temperature))"," shows that the type is ",[23,825,20],{},[45,827,829],{"id":828},"important-beginner-note-about-precision","Important beginner note about precision",[14,831,832],{},"Floats are very useful, but they are not always perfectly exact.",[14,834,835],{},"Some decimal values cannot be stored exactly in binary form. Because of that, you may sometimes see small unexpected results.",[14,837,356],{},[126,839,841],{"className":128,"code":840,"language":130,"meta":131,"style":131},"print(0.1 + 0.2)\n",[23,842,843],{"__ignoreMap":131},[135,844,845,847,849,852,854,857],{"class":137,"line":138},[135,846,157],{"class":156},[135,848,161],{"class":160},[135,850,851],{"class":149},"0.1",[135,853,669],{"class":145},[135,855,856],{"class":149}," 0.2",[135,858,168],{"class":160},[14,860,189],{},[126,862,864],{"className":128,"code":863,"language":130,"meta":131,"style":131},"0.30000000000000004\n",[23,865,866],{"__ignoreMap":131},[135,867,868],{"class":137,"line":138},[135,869,863],{"class":149},[14,871,872,873,876],{},"This does ",[18,874,875],{},"not"," mean Python is broken. It means floats have small precision limits.",[14,878,879],{},"For beginner code, a practical fix is often to format or round the result:",[126,881,883],{"className":128,"code":882,"language":130,"meta":131,"style":131},"print(round(0.1 + 0.2, 2))\n",[23,884,885],{"__ignoreMap":131},[135,886,887,889,891,894,896,898,900,902,905,907],{"class":137,"line":138},[135,888,157],{"class":156},[135,890,161],{"class":160},[135,892,893],{"class":156},"round",[135,895,161],{"class":160},[135,897,851],{"class":149},[135,899,669],{"class":145},[135,901,856],{"class":149},[135,903,904],{"class":160},",",[135,906,666],{"class":149},[135,908,186],{"class":160},[14,910,189],{},[126,912,914],{"className":128,"code":913,"language":130,"meta":131,"style":131},"0.3\n",[23,915,916],{"__ignoreMap":131},[135,917,918],{"class":137,"line":138},[135,919,913],{"class":149},[14,921,922,923,34],{},"You can learn more on the ",[88,924,926,929],{"href":925},"\u002Freference\u002Fpython-round-function-explained\u002F",[23,927,928],{},"round()"," function",[45,931,933],{"id":932},"converting-values-to-float","Converting values to float",[14,935,936,937,942],{},"You can use ",[88,938,940],{"href":939},"\u002Freference\u002Fpython-float-function-explained\u002F",[23,941,353],{}," to convert other values into floats.",[14,944,56],{},[126,946,948],{"className":128,"code":947,"language":130,"meta":131,"style":131},"print(float(\"3.5\"))\nprint(float(7))\n",[23,949,950,970],{"__ignoreMap":131},[135,951,952,954,956,958,960,963,966,968],{"class":137,"line":138},[135,953,157],{"class":156},[135,955,161],{"class":160},[135,957,20],{"class":178},[135,959,161],{"class":160},[135,961,962],{"class":211},"\"",[135,964,965],{"class":215},"3.5",[135,967,962],{"class":211},[135,969,186],{"class":160},[135,971,972,974,976,978,980,983],{"class":137,"line":153},[135,973,157],{"class":156},[135,975,161],{"class":160},[135,977,20],{"class":178},[135,979,161],{"class":160},[135,981,982],{"class":149},"7",[135,984,186],{"class":160},[14,986,189],{},[126,988,990],{"className":128,"code":989,"language":130,"meta":131,"style":131},"3.5\n7.0\n",[23,991,992,996],{"__ignoreMap":131},[135,993,994],{"class":137,"line":138},[135,995,462],{"class":149},[135,997,998],{"class":137,"line":153},[135,999,1000],{"class":149},"7.0\n",[14,1002,1003],{},"This is common when working with user input:",[126,1005,1007],{"className":128,"code":1006,"language":130,"meta":131,"style":131},"user_text = \"8.25\"\nnumber = float(user_text)\n\nprint(number)\nprint(type(number))\n",[23,1008,1009,1025,1042,1046,1057],{"__ignoreMap":131},[135,1010,1011,1014,1016,1019,1022],{"class":137,"line":138},[135,1012,1013],{"class":141},"user_text ",[135,1015,146],{"class":145},[135,1017,1018],{"class":211}," \"",[135,1020,1021],{"class":215},"8.25",[135,1023,1024],{"class":211},"\"\n",[135,1026,1027,1030,1032,1035,1037,1040],{"class":137,"line":153},[135,1028,1029],{"class":141},"number ",[135,1031,146],{"class":145},[135,1033,1034],{"class":178}," float",[135,1036,161],{"class":160},[135,1038,1039],{"class":164},"user_text",[135,1041,168],{"class":160},[135,1043,1044],{"class":137,"line":171},[135,1045,404],{"emptyLinePlaceholder":403},[135,1047,1048,1050,1052,1055],{"class":137,"line":400},[135,1049,157],{"class":156},[135,1051,161],{"class":160},[135,1053,1054],{"class":164},"number",[135,1056,168],{"class":160},[135,1058,1059,1061,1063,1065,1067,1069],{"class":137,"line":407},[135,1060,157],{"class":156},[135,1062,161],{"class":160},[135,1064,179],{"class":178},[135,1066,161],{"class":160},[135,1068,1054],{"class":164},[135,1070,186],{"class":160},[14,1072,189],{},[126,1074,1076],{"className":128,"code":1075,"language":130,"meta":131,"style":131},"8.25\n\u003Cclass 'float'>\n",[23,1077,1078,1083],{"__ignoreMap":131},[135,1079,1080],{"class":137,"line":138},[135,1081,1082],{"class":149},"8.25\n",[135,1084,1085,1087,1089,1091,1093,1095],{"class":137,"line":153},[135,1086,204],{"class":145},[135,1088,208],{"class":207},[135,1090,212],{"class":211},[135,1092,20],{"class":215},[135,1094,218],{"class":211},[135,1096,221],{"class":145},[14,1098,1099,1100,231],{},"If the text is not a valid number, Python raises a ",[23,1101,1102],{},"ValueError",[126,1104,1106],{"className":128,"code":1105,"language":130,"meta":131,"style":131},"float(\"hello\")\n",[23,1107,1108],{"__ignoreMap":131},[135,1109,1110,1112,1114,1116,1119,1121],{"class":137,"line":138},[135,1111,20],{"class":178},[135,1113,161],{"class":160},[135,1115,962],{"class":211},[135,1117,1118],{"class":215},"hello",[135,1120,962],{"class":211},[135,1122,168],{"class":160},[14,1124,1125],{},"Error:",[126,1127,1129],{"className":128,"code":1128,"language":130,"meta":131,"style":131},"ValueError: could not convert string to float: 'hello'\n",[23,1130,1131],{"__ignoreMap":131},[135,1132,1133,1135,1137,1140,1142,1145,1147,1149,1151,1153],{"class":137,"line":138},[135,1134,1102],{"class":178},[135,1136,231],{"class":160},[135,1138,1139],{"class":141}," could ",[135,1141,875],{"class":145},[135,1143,1144],{"class":141}," convert string to ",[135,1146,20],{"class":178},[135,1148,231],{"class":160},[135,1150,212],{"class":211},[135,1152,1118],{"class":215},[135,1154,1155],{"class":211},"'\n",[14,1157,1158,1159,1163,1164,34],{},"If you need help with that, see ",[88,1160,1162],{"href":1161},"\u002Ferrors\u002Fvalueerror-could-not-convert-string-to-float-fix\u002F","ValueError: could not convert string to float"," or ",[88,1165,1167],{"href":1166},"\u002Fhow-to\u002Fhow-to-convert-string-to-float-in-python\u002F","how to convert a string to float in Python",[45,1169,1171],{"id":1170},"common-mistakes","Common mistakes",[14,1173,1174],{},"Beginners often run into these problems:",[58,1176,1177,1182,1190,1193],{},[61,1178,1179,1180],{},"Thinking every number is an ",[23,1181,325],{},[61,1183,1184,1185,645,1187,1189],{},"Assuming ",[23,1186,277],{},[23,1188,77],{}," are the same type",[61,1191,1192],{},"Expecting decimal math to always be perfectly exact",[61,1194,1195,1196],{},"Trying to convert non-number text with ",[23,1197,353],{},[14,1199,1200],{},"Useful checks:",[126,1202,1204],{"className":128,"code":1203,"language":130,"meta":131,"style":131},"print(type(3.14))\nprint(type(5.0))\nprint(float(\"3.5\"))\nprint(0.1 + 0.2)\nprint(round(0.1 + 0.2, 2))\n",[23,1205,1206,1220,1234,1252,1266],{"__ignoreMap":131},[135,1207,1208,1210,1212,1214,1216,1218],{"class":137,"line":138},[135,1209,157],{"class":156},[135,1211,161],{"class":160},[135,1213,179],{"class":178},[135,1215,161],{"class":160},[135,1217,25],{"class":149},[135,1219,186],{"class":160},[135,1221,1222,1224,1226,1228,1230,1232],{"class":137,"line":153},[135,1223,157],{"class":156},[135,1225,161],{"class":160},[135,1227,179],{"class":178},[135,1229,161],{"class":160},[135,1231,77],{"class":149},[135,1233,186],{"class":160},[135,1235,1236,1238,1240,1242,1244,1246,1248,1250],{"class":137,"line":171},[135,1237,157],{"class":156},[135,1239,161],{"class":160},[135,1241,20],{"class":178},[135,1243,161],{"class":160},[135,1245,962],{"class":211},[135,1247,965],{"class":215},[135,1249,962],{"class":211},[135,1251,186],{"class":160},[135,1253,1254,1256,1258,1260,1262,1264],{"class":137,"line":400},[135,1255,157],{"class":156},[135,1257,161],{"class":160},[135,1259,851],{"class":149},[135,1261,669],{"class":145},[135,1263,856],{"class":149},[135,1265,168],{"class":160},[135,1267,1268,1270,1272,1274,1276,1278,1280,1282,1284,1286],{"class":137,"line":407},[135,1269,157],{"class":156},[135,1271,161],{"class":160},[135,1273,893],{"class":156},[135,1275,161],{"class":160},[135,1277,851],{"class":149},[135,1279,669],{"class":145},[135,1281,856],{"class":149},[135,1283,904],{"class":160},[135,1285,666],{"class":149},[135,1287,186],{"class":160},[14,1289,1290],{},"These small tests help you quickly see:",[58,1292,1293,1296,1299],{},[61,1294,1295],{},"whether a value is a float",[61,1297,1298],{},"how conversion works",[61,1300,1301],{},"how precision can affect output",[45,1303,1305],{"id":1304},"faq","FAQ",[1307,1308,1310],"h3",{"id":1309},"is-5-a-float-in-python","Is 5 a float in Python?",[14,1312,1313,1314,1316,1317,1319,1320,1322,1323,34],{},"No. ",[23,1315,277],{}," is an ",[23,1318,325],{},". ",[23,1321,77],{}," is a ",[23,1324,20],{},[1307,1326,1328],{"id":1327},"is-50-the-same-as-5","Is 5.0 the same as 5?",[14,1330,1331,1332,645,1334,34],{},"They can compare as equal in value, but they are different types: ",[23,1333,20],{},[23,1335,325],{},[1307,1337,1339],{"id":1338},"how-do-i-create-a-float-in-python","How do I create a float in Python?",[14,1341,1342,1343,1345,1346,34],{},"Write a number with a decimal point, like ",[23,1344,29],{},", or convert a value with ",[23,1347,353],{},[1307,1349,1351],{"id":1350},"why-does-01-02-give-a-strange-result","Why does 0.1 + 0.2 give a strange result?",[14,1353,1354],{},"Floats cannot store some decimal values exactly, so small precision differences can appear.",[1307,1356,1358],{"id":1357},"can-i-convert-a-string-to-a-float","Can I convert a string to a float?",[14,1360,1361,1362,1365,1366,34],{},"Yes. Use ",[23,1363,1364],{},"float(\"3.14\")",". If the text is not a valid number, Python raises a ",[23,1367,1102],{},[45,1369,1371],{"id":1370},"see-also","See also",[58,1373,1374,1379,1383,1391,1396,1402,1408],{},[61,1375,1376],{},[88,1377,1378],{"href":90},"What is an integer in Python?",[61,1380,1381],{},[88,1382,480],{"href":479},[61,1384,1385],{},[88,1386,1387,1388,1390],{"href":939},"Python ",[23,1389,353],{}," function explained",[61,1392,1393],{},[88,1394,1395],{"href":1166},"How to convert string to float in Python",[61,1397,1398],{},[88,1399,1387,1400,1390],{"href":227},[23,1401,230],{},[61,1403,1404],{},[88,1405,1387,1406,1390],{"href":925},[23,1407,928],{},[61,1409,1410],{},[88,1411,1162],{"href":1161},[1413,1414,1415],"style",{},"html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .smGrS, html code.shiki .smGrS{--shiki-light:#39ADB5;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .srdBf, html code.shiki .srdBf{--shiki-light:#F76D47;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sptTA, html code.shiki .sptTA{--shiki-light:#6182B8;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sP7_E, html code.shiki .sP7_E{--shiki-light:#39ADB5;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .slqww, html code.shiki .slqww{--shiki-light:#6182B8;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sZMiF, html code.shiki .sZMiF{--shiki-light:#E2931D;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sbsja, html code.shiki .sbsja{--shiki-light:#9C3EDA;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sjJ54, html code.shiki .sjJ54{--shiki-light:#39ADB5;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .s_sjI, html code.shiki .s_sjI{--shiki-light:#91B859;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .s39Yj, html code.shiki .s39Yj{--shiki-light:#39ADB5;--shiki-default:#005CC5;--shiki-dark:#79B8FF}",{"title":131,"searchDepth":153,"depth":153,"links":1417},[1418,1419,1420,1421,1422,1423,1424,1425,1426,1433],{"id":47,"depth":153,"text":48},{"id":94,"depth":153,"text":95},{"id":332,"depth":153,"text":333},{"id":483,"depth":153,"text":484},{"id":726,"depth":153,"text":727},{"id":828,"depth":153,"text":829},{"id":932,"depth":153,"text":933},{"id":1170,"depth":153,"text":1171},{"id":1304,"depth":153,"text":1305,"children":1427},[1428,1429,1430,1431,1432],{"id":1309,"depth":171,"text":1310},{"id":1327,"depth":171,"text":1328},{"id":1338,"depth":171,"text":1339},{"id":1350,"depth":171,"text":1351},{"id":1357,"depth":171,"text":1358},{"id":1370,"depth":153,"text":1371},"Master what is a float in python in our comprehensive Python beginner guide.","md",{},"\u002Fglossary\u002Fwhat-is-a-float-in-python",{"title":5,"description":1434},"glossary\u002Fwhat-is-a-float-in-python","dCyJxFDCAXd3R-MHnc95fAIXrH_sURhodDlK2vHQeKs",1777585494155]