decimal

Java: Format double with decimals

岁酱吖の 提交于 2019-12-24 09:49:12
问题 In Objective C I have been using this code to format a value so that a value with zero decimals will be written without decimals and a value with decimals will be written with one decimal: CGFloat value = 1.5; return [NSString stringWithFormat:@"%.*f",(value != floor(value)),value]; //If value == 1.5 the output will be 1.5 //If value == 1.0 the output will be 1 I need to do the same thing for a double value in Java, I tried the following but that is not working: return String.format("%.*f",

How to determine whether a variable is a decimal and it is less than 0.01 in PHP?

拥有回忆 提交于 2019-12-24 09:40:13
问题 How to determine whether a variable is a decimal and it is less than 0.01 in PHP? If I write if($balance<0.01) Will a true value be returned if $balance is not a decimal at all? 回答1: use if( is_numeric($balance) && $balance < 0.01 ) http://php.net/manual/de/function.is-numeric.php 回答2: The value of $balance will be typecasted to whatever is needed for the comparison. In your case, any integer will do, e.g. a $balance of 1 , 1.1 or '1' will all evaluate to false , regardless of their initial

Testing differences between SqlDecimal and C# Decimal

夙愿已清 提交于 2019-12-24 09:07:13
问题 I'm trying to validate that a decimal in c# will fit into a db column decimal. The SqlDecimal object allows you to pass in a precision and scale as well as the decimal bits to the constructor. I know the size of the column and so before we write the data I check each input so I can produce business required output. In this case we are storing a percent, so the precision is 13 and the scale is 10 . I have a testing harness that I've condensed below into a unti test for SO. This sample is

Testing differences between SqlDecimal and C# Decimal

蓝咒 提交于 2019-12-24 09:05:01
问题 I'm trying to validate that a decimal in c# will fit into a db column decimal. The SqlDecimal object allows you to pass in a precision and scale as well as the decimal bits to the constructor. I know the size of the column and so before we write the data I check each input so I can produce business required output. In this case we are storing a percent, so the precision is 13 and the scale is 10 . I have a testing harness that I've condensed below into a unti test for SO. This sample is

Convert decimal MAC address into hexadecimal MAC address

痞子三分冷 提交于 2019-12-24 08:52:25
问题 I have been searching for a method to convert a decimal MAC address into a hex one. So for example 170.187.204.0.17.34 to AA:BB:CC:00:11:22 . Credits goes to Convert HEX to Decimal value? w/ an example. I put my decimal value into columnA (starting A2) and the hexadecimal equivalent should go into columnB (starting B2). 回答1: With 170.187.204.0.17.34 in A1, apply Text to Columns with . as the delimiter. In A2 copied across to F2: =DEC2HEX(A1) in G2: =A2&":"&B2&":"&C2&":"&D2&":"&E2&":"&F2 Or,

PHP Decimal calculations

时光毁灭记忆、已成空白 提交于 2019-12-24 07:48:52
问题 I was reading that you have to be careful with floating point comparisons and calculations in PHP. I'm not an expert at PHP so I thought I would ask the community what is the best way to do accurate decimal calculations in PHP. I'm developing a timecard application where it calculates all the time entered for the week. Anything over 40 hours is considered overtime. I then want to distribute that overtime back across each time entry based on the percentage that entry is of the total time.

PHP - Summing an array of decimal values

吃可爱长大的小学妹 提交于 2019-12-24 06:38:56
问题 I'm trying to calculate the sum of an array of decimal values in PHP, but for some reason it keeps rounding to integers. for example: $oldArray = array(0.00,1000.11,988.92,978.22,964.01,953.07,948.82,917.26,902.56,913.21,904.08,898.86,892.79); $myVar = 0.0; for($k=1;$k<10;$k++) { $myVar += $oldArray[$k]; } print_r($myVar); $oldArray is actually populated with decimal values from an SQL query (the length of $oldarray is about several hundred, but I want the first 10. In the above example, I'm

How to convert a integers between 0 and 25 to corresponding ASCII characters?

偶尔善良 提交于 2019-12-24 06:12:54
问题 Say I have a number 0 that corresponds to the ASCII character a . How would I go about converting a number in the range 0 to 25 to letters in the alphabet? I have already tried adding 97 to the decimal value, but it just outputs the number+ 97 . typedef enum { a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z } set; void dispSet(set numbers[], int size_numbers) { int i; printf("[ "); for (i = 0; i < size_numbers-1; i++) { printf("%d, ", ((char) numbers[i])+97); }

How to convert a integers between 0 and 25 to corresponding ASCII characters?

送分小仙女□ 提交于 2019-12-24 06:12:51
问题 Say I have a number 0 that corresponds to the ASCII character a . How would I go about converting a number in the range 0 to 25 to letters in the alphabet? I have already tried adding 97 to the decimal value, but it just outputs the number+ 97 . typedef enum { a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z } set; void dispSet(set numbers[], int size_numbers) { int i; printf("[ "); for (i = 0; i < size_numbers-1; i++) { printf("%d, ", ((char) numbers[i])+97); }