decimal

Mysql calculation issues: 1+1=1.999999999

£可爱£侵袭症+ 提交于 2019-12-03 16:15:44
The problem is this, when I add two or more doubles from a table to a view, instead of giving me the right results, it adds a about ten or so more digits. For example 0.5+1.5=1.99999999998 or 5.5+8.5=14.0000000001. Any ideas? (I know this is sort of n00b question and I remember having to deal with stuff like that in the exams at 9th grade, but I just cannot remember how I did it back then :P) http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_format You can format numbers this way if thats what your after? Adding 1 and 1 as floats or doubles should not result in anything but

Rounded decimal in edit form Symfony2 + Doctrine2

前提是你 提交于 2019-12-03 15:08:19
How do I set the decimal precision and scale within the symfony2 entity? I've defined latitude in longitude fields using decimal data type in my entity like this: /** * @ORM\Column(type="decimal", precision="10", scale="6", nullable=true) */ protected $latitude; When persisting new object it saves decimal correctly (I can see 52.406374 in phpMyAdmin). However when displaying edit form the number is rounded to 52,406 and after updating it is stored in mysql as 52.406000. Probably something is wrong with my Doctrine configuration, but I don't know what. Why is the latitude and longitude getting

Converting Decimal to Double in C#?

邮差的信 提交于 2019-12-03 14:20:59
问题 I have a variable which is storing as decimal: decimal firststYrComp = Int16.Parse(tb1stYr.Text.ToString()); Now I have this to get typecasted into Double? How do I do that? Thanks! 回答1: You answered your own question—Just cast it to a double: decimal x = 3.141592654M ; double pi = (double) x ; 回答2: You can use decimal's built in converter. decimal decimalValue = 5; double doubleValue = decimal.ToDouble(decimalValue); 回答3: Just Try Decimal yourDecimal = 3.222222m; Convert.ToDouble(yourDecimal

Common lisp integer to hex conversion

孤街浪徒 提交于 2019-12-03 12:57:43
Is there a similar function to (parse-integer "ff" :radix 16) that will take me back the other way? If I have the int 255 how do I convert it to the string ff? (write-to-string 255 :base 16) You can also use format with the ~X radix designator: CL-USER> (format t "~X" 255) FF NIL To get the leading 0x and a minimum width of, say, four padded with zeros, use CL-USER> (format t "0x~4,'0X" 255) 0x00FF NIL To force the digits from 10 to 15 to be lowercase, use the case conversion directive ~( as follows: CL-USER> (format t "0x~(~4,'0x~)" 255) 0x00ff NIL 来源: https://stackoverflow.com/questions

How do I calculate percentages with decimals in SQL?

随声附和 提交于 2019-12-03 12:41:52
How can i convert this to a decimal in SQL? Below is the equation and i get the answer as 78 (integer) but the real answer is 78.6 (with a decimal) so i need to show this as otherwise the report won't tally up to 100% (100 * [TotalVisit1]/[TotalVisits]) AS Visit1percent Shawn convert(decimal(5,2),(100 * convert(float,[TotalVisit1])/convert(float,[TotalVisits]))) AS Visit1percent Ugly, but it works. Try This: (100.0 * [TotalVisit1]/[TotalVisits]) AS Visit1percent At least in MySQL (if it helps), if you want to use float numbers you had to use a type float field, not the regular int fields. Just

DECIMAL length for microtime(true)?

元气小坏坏 提交于 2019-12-03 12:03:48
I want to store PHP's microtime as my timestamp in MySQL. I've been told it's best to store it in DECIMAL , but I can't find an ideal size. Does anyone know what the maximum size microtime(true) returns, so I can put that as my data type length? Should I choose variable DECIMAL length? tl;dr. Use microtime(false) and store the results in a MySQL bigint as millionths of seconds. Otherwise you have to learn all about floating point arithmetic, which is a big fat hairball. The PHP microtime function grabs the Unix timestamp (currently about hex 50eb7c00 or decimal 1,357,609,984) from one system

decimal in c# misunderstanding?

一笑奈何 提交于 2019-12-03 12:01:36
(while trying to analyze how decimal works ) && after reading @jonskeet article and seeing msdn , and thinking for the last 4 hours , I have some questions : in this link they say something very simple : 1.5 x 10^2 has 2 significant figures 1.50 x 10^2 has 3 significant figures. 1.500 x 10^2 has 4 significant figures etc... ok...we get the idea. from jon's article : sign * mantissa / 10^exponent As usual, the sign is just a single bit, but there are 96 bits of mantissa and 5 bits of exponent ^ _ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^___ ^^^^^ 1 _ 96 5 ok so max mantiss val = 2^96-1 =

How do I format my percent variable to 2 decimal places?

痞子三分冷 提交于 2019-12-03 11:03:45
This program is basically working with text files, reading the data & performing functions: while(s.hasNext()){ name= s.next(); mark= s.nextDouble(); double percent= (mark / tm )*100 ; System.out.println("Student Name : " +name ); System.out.println("Percentage In Exam: " +percent+"%"); System.out.println(" "); } I would like to format the percent value to 2 decimal places but since it's inside a while loop I cannot use the printf. Elliot's answer is of course correct, but for completeness' sake it's worth noting that if you don't want to print the value immediately, but instead hold the

angular.js - decimal numbers in European notation

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 11:00:20
问题 In Angular you can use the currency filter to format a number, like like this: {{service.price | currency: "€ "}} the standard output is € #,##0.00 How can the output be: € #.##0,00 (European notation) 回答1: Angular supports i18n Standard for location | globalization | internationalization. When it comes to number formatting Angular relies on $locale service and more specifically on the property NUMBER_FORMATS . The currency symbol by itself will not change the numbering formatting unless you

Convert string to decimal number in ruby

旧城冷巷雨未停 提交于 2019-12-03 10:24:39
问题 I need to work with decimals. In my program, the user need to put a number with decimals to convert that number. The problem is: If I try to convert the argument into a number I get a integer without decimals. # ARGV[0] is: 44.33 size = ARGV[0] puts size.to_i # size is: 44 # :( 回答1: You call to_i , you get integer. Try calling to_f , you should get a float. For more string conversion methods, look here. 回答2: If you want more accurate answer with the calculation to avoid bug like this https:/