double

Round Issue in swift

笑着哭i 提交于 2019-12-09 02:03:48
问题 I have this Info. let params2: [String: AnyObject] = [ "app_token": myapptoken, "member_access_token": accessToken!, "pay_process": 0, "payamount_credit": 9.87 //hardcode ] When print params2 The result is ["app_token": myapptoken, "member_access_token": accessToken, "payamount_credit": 9.869999999999999, "pay_process": 0] The "payamount_credit": 9.87 now is "payamount_credit": 9.869999999999999 I have tried all the ways that exist round but behaves the same. NSString(format: "%.\2f", 9.87)

How to get double touch position in android?

空扰寡人 提交于 2019-12-09 01:52:35
问题 I need to get the positions of each touch when a double touch has done I know that you can get the position of one touch with: int x = (int)event.getX(); int y = (int)event.getY(); how can I get a second x and y? 回答1: event.getPointerCount() will tell you how many touch points there are. To get the other ones, just use an index value in the "Get" method: x0 = event.getX(0); x1 = event.getX(1); ... 回答2: Why dont you use a logic inside an onTouch function. Use static variable and keep a count

Android - SharedPreference converting to Double

让人想犯罪 __ 提交于 2019-12-09 01:40:08
问题 Basically i have a valued saved into shared preference as a string. I am retrieving the value saved, and am trying to use it in a calculation. How can i convert this so that it is seen as a double instead of a string? Once the value is retrieved after the calculation, the new value is saved back into the sharedpreference under the same value. I hope you can understand, been having trouble with this! SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences

Fast real valued random generator in java

走远了吗. 提交于 2019-12-08 23:27:49
问题 java.util.Random.nextDouble() is slow for me and I need something really fast. I did some google search and I've found only integers based fast random generators. Is here anything for real numbers from interval <0, 1) ? 回答1: If you need something fast and have access to Java8, I can recommend the java.utils SplitableRandom. It is faster (~twice as fast) and has better statistical distribution. If you need a even faster or better algorithm I can recommend one of these specialized XorShift

Formatting a double and not rounding off

可紊 提交于 2019-12-08 22:29:18
问题 I need to format (and not round off) a double to 2 decimal places. I tried with: String s1 = "10.126"; Double f1 = Double.parseDouble(s1); DecimalFormat df = new DecimalFormat(".00"); System.out.println("f1"+df.format(f1)); Result: 10.13 But I require the output to be 10.12 回答1: Call setRoundingMode to set the RoundingMode appropriately: String s1 = "10.126"; Double f1 = Double.parseDouble(s1); DecimalFormat df = new DecimalFormat(".00"); df.setRoundingMode(RoundingMode.DOWN); // Note this

Double.doubleToLongBits equivalent in C#?

筅森魡賤 提交于 2019-12-08 19:17:59
问题 there's a Java method Double.doubleToLongBits that basically gets a double and return a long with the same bits. How can I do it in C#? Thank you 回答1: BitConverter.DoubleToInt64Bits would be a good alternative. http://msdn.microsoft.com/en-us/library/system.bitconverter.doubletoint64bits.aspx 回答2: You'll want BitConverter.DoubleToInt64Bits 来源: https://stackoverflow.com/questions/6816691/double-doubletolongbits-equivalent-in-c

IEqualityComparer<double> with a tolerance; how to implement GetHashCode?

痞子三分冷 提交于 2019-12-08 18:51:02
问题 I'm implementing a reusable DoubleEqualityComparer (with a custom tolerance: the "epsilon" constructor parameter) to ease the usage of LINQ with sequences of double. For example: bool myDoubleFound = doubles.Contains(myDouble, new DoubleEqualityComparer(epsilon: 0.01)); What is the right way to implement GetHashCode? Here's the code: public class DoubleEqualityComparer : IEqualityComparer<double>, IEqualityComparer<double?> { private readonly double epsilon; public DoubleEqualityComparer

Double.TryParse() ignores NumberFormatInfo.NumberGroupSizes?

China☆狼群 提交于 2019-12-08 18:33:15
问题 I'd like to know if I'm missing something or not... I'm running under the standard Great British culture. Double result = 0; if (Double.TryParse("1,2,3", NumberStyles.Any, CultureInfo.CurrentCulture, out result)) { Console.WriteLine(result); } Expected output would be nothing... "1,2,3" shouldn't parse as a double. However it does. According to the .NET 2.0 MSDN documentation AllowThousands Indicates that the numeric string can have group separators; for example, separating the hundreds from

More precision than double in swift

。_饼干妹妹 提交于 2019-12-08 17:45:33
问题 Are there are any floating points more accurate than Double available in Swift? I know that in C there is the long double , but I can't seem to find its equivalent in Apple's new programming language. Any help would be greatly appreciated! 回答1: Yes there is! There is Float80 exactly for that, it stores 80 bits (duh), 10 bytes. You can use it like any other floating point type. Note that there are Float32 , Float64 and Float80 in Swift, where Float32 is just a typealias for Float and Float64

How to get “shortest” BigDecimal that uniquely determines a given double

放肆的年华 提交于 2019-12-08 17:26:47
问题 Basically, I'm curious on how to get hold of new BigDecimal(Double.toString(d)) without going through the process of creating a string. The documentation for Double.toString is quite complex (and interesting). As I understand it, the method does not actually return the string representation of the number actually represented by the given double, but the string representation of the (near by) shortest real number that uniquely identifies the given double . (I don't actually need this. If I did