python中有数量限制吗?

时间:2017-01-09 17:41:01

标签: python pi

我已经制作了一个Python 3程序来计算学校项目的pi,但它总是停在16位小数。 python中的数字长度是否有限制?如果是这样,我可以使用哪种语言让我继续?

/dist

1 个答案:

答案 0 :(得分:9)

如果使用整数和Python 3.x,则没有任何限制。但是,使用浮点数得到的精度有限。 Python create table ##aw ( strr varchar(max) ) insert ##aw values('<p1:UniversalInterchange xmlns:p1="http://www.cargowise.com/Schemas/Native"><Header xmlns=""><SenderID/><RecipientID/></Header><Body xmlns=""><UniversalEvent><Event><EventType>DEP</EventType><EventTime>2016-02-04T13:37:00</EventTime><ContextCollection><Context><Type>MAWBNumber</Type><Value>057-23154670</Value></Context><Context><Type>MAWBOriginIATAAirportCode</Type><Value>IAD</Value></Context><Context><Type>MAWBDestinationIATAAirportCode</Type><Value>TUN</Value></Context><Context><Type>MAWBNumberOfPieces</Type><Value>1</Value></Context><Context><Type>OtherServiceInfo</Type><Value>PRD-XPS </Value></Context><Context><Type>SourceEventCode</Type><Value>DEP</Value></Context><Context><Type>NumberOfPieces</Type><Value>1</Value></Context><Context><Type>WeightOfGoods</Type><Value>2KG</Value></Context><Context><Type>IATACarrierCode</Type><Value>AF</Value></Context><Context><Type>FlightNumber</Type><Value>1184</Value></Context><Context><Type>FlightDate</Type><Value>04-FEB-2016</Value></Context><Context><Type>OriginIATAAirportCode</Type><Value>CDG</Value></Context><Context><Type>DestinationIATAAirportCode</Type><Value>TUN</Value></Context><Context><Type>TimeOfDeparture</Type><Value>2016-02-04T13:37:00</Value></Context><Context><Type>TimeOfArrival</Type><Value>2016-02-04T15:40:00</Value></Context></ContextCollection><AdditionalFieldsToUpdateCollection><AdditionalFieldsToUpdate><Type>JobConsolTransport.JW_ATD</Type><Value>2016-02-04T13:37:00</Value></AdditionalFieldsToUpdate></AdditionalFieldsToUpdateCollection></Event></UniversalEvent></Body></p1:UniversalInterchange>') select substring(strr, charindex('IATACarrierCode</Type><Value>', strr) + len('IATACarrierCode</Type><Value>'), 2) from ##aw (如float)实际上是一个C 3.14,其精度约为16位小数。正如您所说。

您可以使用double模块以任意精度创建和使用其他浮点数。示例代码:

decimal

有关# Normal Python floats a = 0.000000000000000000001 b = 1 + 2*a print(b) # Prints 1.0 # Using Decimal import decimal decimal.getcontext().prec = 100 # Set the precision a = decimal.Decimal('0.000000000000000000001') b = 1 + 2*a print(b) # Prints 1.000000000000000000002 的详细信息,请参阅the docs

相关问题