negative-number

trunc and round function in sql

微笑、不失礼 提交于 2019-12-02 00:52:21
问题 Is trunc and round the same with negative arguments? SQL> select round(123456.76,-4) from dual; ROUND(123456.76,-4) ------------------- 120000 SQL> select trunc(123456.76,-4) from dual; TRUNC(123456.76,-4) ------------------- 120000 回答1: No, behavior depends on the value of the significant digit (the 3rd digit (the 3) is the significant one in your case, as it is below 5 round and trunc do the same ) try select trunc(125456.76,-4) from dual (result is 120000) vs select round(125456.76,-4)

JTextArea only with numbers, but allowing negative values

懵懂的女人 提交于 2019-12-02 00:12:32
问题 I have a JTextArea which only has to accept numbers. This is my code: DocumentFilter onlyNumberFilter = new AxisJTextFilter(); final JTextArea areaTextoXMin = new JTextArea(String.valueOf(xMin)); ((AbstractDocument)areaTextoXMin.getDocument()).setDocumentFilter(onlyNumberFilter); Works OK for positive numbers, but not for negative numbers. How can I fix that? EDIT: Sorry, the AxisJTextFilter was found over the Internet and I forgot about that. Its code is: import javax.swing.text.*; import

trunc and round function in sql

谁都会走 提交于 2019-12-01 20:24:46
Is trunc and round the same with negative arguments? SQL> select round(123456.76,-4) from dual; ROUND(123456.76,-4) ------------------- 120000 SQL> select trunc(123456.76,-4) from dual; TRUNC(123456.76,-4) ------------------- 120000 No, behavior depends on the value of the significant digit (the 3rd digit (the 3) is the significant one in your case, as it is below 5 round and trunc do the same ) try select trunc(125456.76,-4) from dual (result is 120000) vs select round(125456.76,-4) from dual (result is 130000). Now when the significant digit is 5 (or higher) the results of trunc and round

Python: Removing negatives from a list of numbers

假如想象 提交于 2019-12-01 16:40:12
问题 The question is to remove negatives from numbers. When remove_negs([1, 2, 3, -3, 6, -1, -3, 1]) is executed, the result is: [1, 2, 3, 6, -3, 1] . The result is suppose to be [1, 2, 3, 6, 3, 1] . what is happening is that if there are two negative numbers in a row (e.g., -1, -3 ) then the second number will not get removed. def main(): numbers = input("Enter a list of numbers: ") remove_negs(numbers) def remove_negs(num_list): '''Remove the negative numbers from the list num_list.''' for item

Detecting and adjusting for negative zero

谁说胖子不能爱 提交于 2019-12-01 06:05:52
I have some code that has been port from Java to C++ // since this point is a vector from (0,0,0), we can just take the // dot product and compare double r = point.dot(normal); return (r>=0.0); But in C++ r can be either +0.0 or -0.0 , when r equals -0.0 it fails the check. I've tried to adjust for negative zero in the code below but it never hits the DEBUG("Negative zero") line. But r2 does print out equal to +0.0 . // since this point is a vector from (0,0,0), we can just take the // dot product and compare double r = point.dot(normal); if (std::signbit(r)){ double r2 = r*-1; DEBUG("r=%f r=

android parsing negative number strings

孤者浪人 提交于 2019-12-01 05:56:25
问题 How to parse negative number strings? strings may be of the form: -123.23 (123.23) 123.23- is there a class that will convert any of the above strings to a number? if not, what is the best way to do it? 回答1: Building on WarrenFaiths answer you can add this: Double newNumber = 0; if(number.charAt(i).isDigit()){ //parse numeber here using WarrenFaiths method and place the int or float or double newNumber = Double.valueOf(number); }else{ Boolean negative = false; if(number.startsWith("-") ||

Detecting and adjusting for negative zero

我只是一个虾纸丫 提交于 2019-12-01 03:48:31
问题 I have some code that has been port from Java to C++ // since this point is a vector from (0,0,0), we can just take the // dot product and compare double r = point.dot(normal); return (r>=0.0); But in C++ r can be either +0.0 or -0.0 , when r equals -0.0 it fails the check. I've tried to adjust for negative zero in the code below but it never hits the DEBUG("Negative zero") line. But r2 does print out equal to +0.0 . // since this point is a vector from (0,0,0), we can just take the // dot

Random and negative numbers

爱⌒轻易说出口 提交于 2019-12-01 03:34:45
I have to generate numbers in range [-100; +2000] in c++. How can I do this with rand if there is only positive numbers available? Are there any fast ways? Kendrick generate a random number between 0 and 2100 then subtract 100. A quick google search turned up a decent looking article on using Rand(). It includes code examples for working with a specific range at the end of the article. Generate a random number between 0 and 2100, and subtract 100. You can use the C++ TR1 random functions to generate numbers in the desired distribution. std::random_device rseed; std::mt19937 rng(rseed()); std:

Stacked bar charts using python matplotlib for positive and negative values

扶醉桌前 提交于 2019-11-30 15:35:53
问题 I am trying to plot a stacked bar chart with python Matplotlib and I have positive and negative values that I want to draw. I have had a look at other posts talking about how to plot stacked bar charts with positive and negative values, but none of them has done it using Matplotlib so I couldn't find my solution. Stacked bar chart with negative JSON data d3.js stacked bar chart with positive and negative values Highcharts vertical stacked bar chart with negative values, is it possible? I have

How to efficiently compare the sign of two floating-point values while handling negative zeros

南楼画角 提交于 2019-11-30 12:56:57
Given two floating-point numbers, I'm looking for an efficient way to check if they have the same sign, given that if any of the two values is zero (+0.0 or -0.0), they should be considered to have the same sign . For instance, SameSign(1.0, 2.0) should return true SameSign(-1.0, -2.0) should return true SameSign(-1.0, 2.0) should return false SameSign(0.0, 1.0) should return true SameSign(0.0, -1.0) should return true SameSign(-0.0, 1.0) should return true SameSign(-0.0, -1.0) should return true A naive but correct implementation of SameSign in C++ would be: bool SameSign(float a, float b) {