decimal

How Can I Convert Very Large Decimal Numbers to Binary In Java

大兔子大兔子 提交于 2019-12-18 04:23:30
问题 For instance, How would I be able to convert 2^60 or 12345678901234567890123456789012345678901234567890 to binary? Basically, numbers that are too large to represent in Java. Edit: I will be making a class that will be able to represent number that are too large. I'm just having a hard time figuring our how to convert decimal to binary. Edit2: And also, I am not allowed to use BigDecimal, BigInteger, or any other library, sorry for not specifying earlier. 回答1: Try this: new BigDecimal(

Doing exact real number arithmetic with PHP

自作多情 提交于 2019-12-18 04:17:17
问题 What is fastest and most easy way of making basic arithmetic operations on strings representing real numbers in PHP? I have a string representing MySQL's DECIMAL value on which I want to operate and return the result to a database after that. I would like to avoid errors introduced by floating-point real number representation. Is there some standard library like Python's decimal? Are there any FOSS libraries you can recommend? Regards 回答1: You could use the BC math functions: http://www.php

Why does Convert.ToInt32() round to the nearest even number, instead of nearest whole number? [closed]

我的未来我决定 提交于 2019-12-18 03:51:25
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . Looking at the msdn documentation for Convert.ToInt32() it states: If value is halfway between two whole numbers, the even number is

Best way to handle large (UUID) as a MySQL table primary key

守給你的承諾、 提交于 2019-12-18 03:41:29
问题 I have a UUID string that I want to use as my MySQL tables primary key, the UUID is a 32 character hexadecimal string (after '-' characters are stripped). Due to the fact that it is better to use a numeric column (int) as your primary key in a database, I would like to convert this to an integer but not sure of the best way to handle it. Due to the size of the string (ie. uuid='a822ff2bff02461db45ddcd10a2de0c2'), do I need to break this into multiple 'substrings'. I am running PHP on a 32 bit

Best way to handle large (UUID) as a MySQL table primary key

て烟熏妆下的殇ゞ 提交于 2019-12-18 03:41:17
问题 I have a UUID string that I want to use as my MySQL tables primary key, the UUID is a 32 character hexadecimal string (after '-' characters are stripped). Due to the fact that it is better to use a numeric column (int) as your primary key in a database, I would like to convert this to an integer but not sure of the best way to handle it. Due to the size of the string (ie. uuid='a822ff2bff02461db45ddcd10a2de0c2'), do I need to break this into multiple 'substrings'. I am running PHP on a 32 bit

Python float to Decimal conversion

家住魔仙堡 提交于 2019-12-18 01:19:22
问题 Python Decimal doesn't support being constructed from float; it expects that you have to convert float to a string first. This is very inconvenient since standard string formatters for float require that you specify number of decimal places rather than significant places. So if you have a number that could have as many as 15 decimal places you need to format as Decimal(""%.15f"% my_float), which will give you garbage at the 15th decimal place if you also have any significant digits before

Python: Converting string into decimal number

可紊 提交于 2019-12-17 23:17:29
问题 I have a python list with strings in this format: A1 = [' "29.0" ',' "65.2" ',' "75.2" '] How do I convert those strings into decimal numbers to perform arithmetic operations on the list elements? 回答1: If you want the result as the nearest binary floating point number use float : result = [float(x.strip(' "')) for x in A1] If you want the result stored exactly use Decimal instead of float : from decimal import Decimal result = [Decimal(x.strip(' "')) for x in A1] 回答2: You will need to use

How to convert decimal fractions to hexadecimal fractions?

一个人想着一个人 提交于 2019-12-17 22:54:24
问题 So I was thinking, how do you convert a decimal fraction into a hexadecimal fraction ? What are some methods for converting and are there short cuts? 回答1: You can use this algorithm: Take a fractional part of the number (i.e. integer part equals to zero) Multiply by 16 Convert integer part to hexadecimal and put it down Go to step 1 For instance, let's find out hexadecimal representation for pi = 3.141592653589793 ... integer part is evident - 0x3 ; as for fractional part ( 0.141592653589793

Is there a Math API for Pow(decimal, decimal)

萝らか妹 提交于 2019-12-17 22:38:01
问题 Is there a library for decimal calculation, especially the Pow(decimal, decimal) method? I can't find any. It can be free or commercial, either way, as long as there is one. Note: I can't do it myself, can't use for loops, can't use Math.Pow , Math.Exp or Math.Log , because they all take double s, and I can't use double s. I can't use a serie because it would be as precise as double s. 回答1: One of the multipliyers is a rate : 1/rate^(days/365). The reason there is no decimal power function is

Python convert decimal to hex

最后都变了- 提交于 2019-12-17 21:53:46
问题 I have a function here that converts decimal to hex but it prints it in reverse order. How would I fix it? def ChangeHex(n): if (n < 0): print(0) elif (n<=1): print(n) else: x =(n%16) if (x < 10): print(x), if (x == 10): print("A"), if (x == 11): print("B"), if (x == 12): print("C"), if (x == 13): print("D"), if (x == 14): print("E"), if (x == 15): print ("F"), ChangeHex( n / 16 ) 回答1: If you want to code this yourself instead of using the built-in function hex() , you can simply do the