decimal

mySQL format number output , thousands separator

时光毁灭记忆、已成空白 提交于 2019-12-06 04:31:57
I have a mySQL query which is outputting decimal fields with a comma. SELECT Metals.Metal, FORMAT(Fixes.GBPam, 3) AS AM, FORMAT(Fixes.GBPpm, 3) AS PM, DATE_FORMAT(Fixes.DateTime, '%d-%m-%y') AS Date FROM Fixes, Metals WHERE Metals.Id = Fixes.Metals_Id Fields GBPam and GBPpm are both of type decimal(10,5) Now I want columns AM and PM to be formatted to 3 decimal places in my sql query - Correct I want values in the thousands to be formatted as xxxx.xxx and not x,xxx.xxx - Incorrect Example output from mysql query: Metal AM PM Date Gold 1,081.334 NULL 11-09-12 Silver 21.009 NULL 10-09-12

Converting a decimal to a hexadecimal number

家住魔仙堡 提交于 2019-12-06 04:06:19
问题 Why we use + 55 for converting decimal to hex num . in this code we use +48 to convert integer to character . when temp < 10 . But when temp > =10 we use +55 . what does it mean by +55 ? #include<stdio.h> int main(){ long int decimalNumber,remainder,quotient; int i=1,j,temp; char hexadecimalNumber[100]; printf("Enter any decimal number: "); scanf("%ld",&decimalNumber); quotient = decimalNumber; while(quotient!=0){ temp = quotient % 16; //To convert integer into character if( temp < 10) temp

MySQL decimal fields returned as strings in PHP

帅比萌擦擦* 提交于 2019-12-06 03:42:56
问题 By default mysqli returns all values as strings, the MYSQLI_OPT_INT_AND_FLOAT_NATIVE option allows you to convert ints and floats to their appropriate types. Though this does not affect decimal fields. Is there a way to automatically cast all decimal fields to a php float type without manually calling $value = (float) $row->some_decimal_field ? 回答1: I highly doubt it. Decimals use fixed point math, and there is no data type in PHP that can provide this. Floats come close, but they are in fact

Why is the result of Decimal.MaxValue - 0.5 an integer?

坚强是说给别人听的谎言 提交于 2019-12-06 03:22:20
问题 I was playing with decimal today. I noticed this: Decimal.MaxValue 79228162514264337593543950335 Decimal.MaxValue - 0.5m 79228162514264337593543950334 The following code prints true. static void Main(string[] args) { decimal d = Decimal.MaxValue - 0.5M; var b = d % 1 == 0; Console.WriteLine(b); } I am sure there is a reason behind this but I don't know what it is. 回答1: The decimal type uses 96 bits to store the sequence of digits (ref), plus a sign (1 bit) and a scaling factor that specifies

Why does Convert.ToDecimal(Double) round to 15 significant figures?

风格不统一 提交于 2019-12-06 02:08:17
I have a double with 17 digits after the decimal point, i.e.: double myDouble = 0.12345678901234567; If I convert this to a decimal like this: decimal myDecimal = Convert.ToDecimal(myDouble); then the value of myDecimal is rounded, as per the Convert.ToDecimal documentation, to 15 digits (i.e. 0.0123456789012345 ). My question is, why is this rounding performed? I understand that if my original number could be accurately represented in base 10 and I was trying to store it as a double , then we could only have confidence in the first 15 digits. The final two digits would be subject to rounding

Can hexadecimal numbers be added/subtracted with decimal numbers?

喜夏-厌秋 提交于 2019-12-06 02:05:31
When programming in C, say if I have integer h as a hexadecimal value and integer d as a decimal number. Can I do addition or subtraction between h and d? Or do they have have to be in the same number system? Yes, you can write: int x = 100 - 0x100 + 0100; That mixes decimal with hex and octal. The values are all converted to binary anyway before the calculation occurs (and the compiler will do the calculation in this example; it won't be evaluated at runtime). And any of the constants can be replaced by an int value that was assigned the appropriate value: int d = 100; int h = 0x100; int o =

Why doesn't python decimal library return the specified number of signficant figures for some inputs

一个人想着一个人 提交于 2019-12-06 02:05:00
NB : this question is about significant figures . It is not a question about "digits after the decimal point" or anything like that. EDIT : This question is not a duplicate of Significant figures in the decimal module . The two questions are asking about entirely different problems. I want to know why the function about does not return the desired value for a specific input. None of the answers to Significant figures in the decimal module address this question. The following function is supposed to return a string representation of a float with the specified number of significant figures:

cv::Mat matrix, HOW TO Reduce digits to the right of the decimal point in cv::Mat?

半腔热情 提交于 2019-12-06 01:41:49
问题 I have an app that prints a 3x3 cv::Mat on the iPhone screen. I need to reduce the decimals, as the screen is not so big, see: [1.004596557012473, -0.003116992336797859, 5.936915104939593; -0.007241746117066327, 0.9973985665720294, -0.2118670500989478; 1.477734234970711e-05, -1.03363734495053e-05, 1.000089074805124] so I would like to reduce the decimals .4 or .6 or six decimals. Any ideas? Cheers 回答1: If you were using printf cv::Mat data(3, 3, CV_64FC1); for (int y = 0; y < data.rows; ++y)

Why is System.Math and for example MathNet.Numerics based on double?

折月煮酒 提交于 2019-12-05 23:02:11
问题 All the methods in System.Math takes double as parameters and returns parameters. The constants are also of type double . I checked out MathNet.Numerics, and the same seems to be the case there. Why is this? Especially for constants. Isn't decimal supposed to be more exact? Wouldn't that often be kind of useful when doing calculations? 回答1: This is a classic speed-versus-accuracy trade off. However, keep in mind that for PI, for example, the most digits you will ever need is 41. The largest

NumberFormatException on European Versions of Android?

家住魔仙堡 提交于 2019-12-05 22:39:24
I have an app which runs the following two lines of code upon starting: DecimalFormat decim = new DecimalFormat("#.00"); return Double.parseDouble(decim.format(totalNumberOfCredits)); When I start the app on my American phone, the value of decim.format(totalNumberOfCredits) is .00 . However, in my Google Play Developer Console, I have a dozen crashes, all of which look like this: Caused by: java.lang.NumberFormatException: Invalid double: ",00" at java.lang.StringToReal.invalidReal(StringToReal.java:63) at java.lang.StringToReal.parseDouble(StringToReal.java:269) at java.lang.Double