double

Should we generally use float literals for floats instead of the simpler double literals?

≯℡__Kan透↙ 提交于 2019-12-28 02:44:29
问题 In C++ (or maybe only our compilers VC8 and VC10) 3.14 is a double literal and 3.14f is a float literal. Now I have a colleague that stated: We should use float-literals for float calculations and double-literals for double calculations as this could have an impact on the precision of a calculation when constants are used in a calcualtion. Specifically, I think he meant: double d1, d2; float f1, f2; ... init and stuff ... f1 = 3.1415 * f2; f1 = 3.1415f * f2; // any difference? d1 = 3.1415 *

Is it valid to compare a double with an int in java?

Deadly 提交于 2019-12-27 22:39:29
问题 Utilities.getDistance(uni, enemyuni) <= uni.getAttackRange() Utilities.getDistance returns double and getAttackRange returns int. The above code is part of an if statement and it needs to be true. So is the comparison valid? Thanks 回答1: Yes, it's valid - it will promote the int to a double before performing the comparison. See JLS section 15.20.1 (Numerical Comparison Operators) which links to JLS section 5.6.2 (Binary Numeric Promotion). From the latter: Widening primitive conversion (§5.1.2

How to make C++ cout not use scientific notation

♀尐吖头ヾ 提交于 2019-12-27 14:46:14
问题 double x = 1500; for(int k = 0; k<10 ; k++){ double t = 0; for(int i=0; i<12; i++){ t += x * 0.0675; x += x * 0.0675; } cout<<"Bas ana: "<<x<<"\tSon faiz: "<<t<<"\tSon ana: "<<x+t<<endl; } this the output Bas ana: 3284.78 Son faiz: 1784.78 Son ana: 5069.55 Bas ana: 7193.17 Son faiz: 3908.4 Son ana: 11101.6 Bas ana: 15752 Son faiz: 8558.8 Son ana: 24310.8 Bas ana: 34494.5 Son faiz: 18742.5 Son ana: 53237 Bas ana: 75537.8 Son faiz: 41043.3 Son ana: 116581 Bas ana: 165417 Son faiz: 89878.7 Son

Java:Why should we use BigDecimal instead of Double in the real world? [duplicate]

[亡魂溺海] 提交于 2019-12-27 10:44:29
问题 This question already has answers here : Double vs. BigDecimal? (6 answers) Closed 4 years ago . When dealing with real world monetary values, I am advised to use BigDecimal instead of Double.But I have not got a convincing explanation except, "It is normally done that way". Can you please throw light on this question? 回答1: It's called loss of precision and is very noticeable when working with either very big numbers or very small numbers. The binary representation of decimal numbers with a

Parsing all the doubles from a string C# [closed]

情到浓时终转凉″ 提交于 2019-12-26 18:22:06
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago . I actually have strings formed like this one: { Desc = Marketcap, Val = 1,270.10 BTC 706,709.04 USD 508,040.00 EUR 4,381,184.55 CNY 425,238.14 GBP 627,638.19 CHF 785,601.09 CAD 72,442,058.40 JPY 787,357.97 AUD 7,732,676.06 ZAR } I'd need to parse out all the doubles in it, and I am actually stuck

Strange double-to-string conversion

醉酒当歌 提交于 2019-12-26 01:29:57
问题 I am using the following code to populate a Spinner in one of my Activities... for( double i = 0; i < 10 ; i+=0.1 ) { rVoltsList.add( Double.toString( i ) ); } Spinner rVoltsSpinner = (Spinner) findViewById( R.id.recloseVoltsSpinner ); ArrayAdapter<String> rVoltsAdapter = new ArrayAdapter<String>( this, android.R.layout.simple_spinner_item, rVoltsList ); rVoltsSpinner.setAdapter( rVoltsAdapter ); I was assuming this would give me a list as follows : 0.0, 0.1, 0.2, 0.3, 0.4, and so on. However

Strange double-to-string conversion

大兔子大兔子 提交于 2019-12-26 01:29:43
问题 I am using the following code to populate a Spinner in one of my Activities... for( double i = 0; i < 10 ; i+=0.1 ) { rVoltsList.add( Double.toString( i ) ); } Spinner rVoltsSpinner = (Spinner) findViewById( R.id.recloseVoltsSpinner ); ArrayAdapter<String> rVoltsAdapter = new ArrayAdapter<String>( this, android.R.layout.simple_spinner_item, rVoltsList ); rVoltsSpinner.setAdapter( rVoltsAdapter ); I was assuming this would give me a list as follows : 0.0, 0.1, 0.2, 0.3, 0.4, and so on. However

Strange double-to-string conversion

三世轮回 提交于 2019-12-26 01:29:23
问题 I am using the following code to populate a Spinner in one of my Activities... for( double i = 0; i < 10 ; i+=0.1 ) { rVoltsList.add( Double.toString( i ) ); } Spinner rVoltsSpinner = (Spinner) findViewById( R.id.recloseVoltsSpinner ); ArrayAdapter<String> rVoltsAdapter = new ArrayAdapter<String>( this, android.R.layout.simple_spinner_item, rVoltsList ); rVoltsSpinner.setAdapter( rVoltsAdapter ); I was assuming this would give me a list as follows : 0.0, 0.1, 0.2, 0.3, 0.4, and so on. However

accessing variables from another method

China☆狼群 提交于 2019-12-25 18:39:04
问题 I'm currently trying to access a double from another load form method. Once I change a check box I wish to add/subtract from this variable. I have commented on both the variable and the problem. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Virtual_Car_Dealer { public partial class BMW : Form { private CarDatabase

Swift is giving non-void return error even though it is set to Double?

情到浓时终转凉″ 提交于 2019-12-25 18:19:25
问题 I am getting this error: /Users/xxxx/Desktop/xxx/xxx/ViewController.swift:43:38: Unexpected non-void return value in void function And others like this even though my functions are set to return Double. This is one of the functions of which this error is appearing in every return. func readWeight() -> Double { let quantityType = HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.bodyMass) let weightQuery = HKSampleQuery(sampleType: quantityType!, predicate: nil, limit: 1,