decimal-point

How to control number of decimal digits in write.table() output?

给你一囗甜甜゛ 提交于 2019-11-28 21:55:11
问题 When working with data (e.g., in data.frame) the user can control displaying digits by using options(digits=3) and listing the data.frame like this. ttf.all When the user needs to paste the data in Excell like this write.table(ttf.all, 'clipboard', sep='\t',row.names=F) The digits parameter is ignored and numbers are not rounded. See nice output > ttf.all year V1.x.x V1.y.x ratio1 V1.x.y V1.y.y ratioR V1.x.x V1.y.x ratioAL V1.x.y V1.y.y ratioRL 1 2006 227 645 35.2 67 645 10.4 150 645 23.3 53

mysql trigger operand should contain 2 columns

岁酱吖の 提交于 2019-11-28 14:29:01
My trigger looks like this: begin IF ((NEW.tgebucht >= NEW.tteilnmax) AND (NEW.tgebucht!=0) AND (OLD.tstatus=0)) THEN SET NEW.tstatus = 1; ELSEIF ((NEW.tgebucht < NEW.tteilnmax) AND (OLD.tstatus=1)) THEN SET NEW.tstatus =0; END IF; IF ((0,25*NEW.tteilnmax)>=(NEW.tteilnmax-NEW.tgebucht)) THEN SET NEW.trestplatze =1; END IF; end And I am getting an error like this: Operand should contain 2 column(s) I am not really sure why, I know it is related to second if but I can't configure where, does anyone has an idea what to change? Am I doing something wrong here? Any help would be appreciated. The

Python, Determine if a string should be converted into Int or Float

 ̄綄美尐妖づ 提交于 2019-11-28 10:54:48
I want to convert a string to the tightest possible datatype: int or float. I have two strings: value1="0.80" #this needs to be a float value2="1.00" #this needs to be an integer. How I can determine that value1 should be Float and value2 should be Integer in Python? def isfloat(x): try: a = float(x) except ValueError: return False else: return True def isint(x): try: a = float(x) b = int(a) except ValueError: return False else: return a == b Python float objects have an is_integer method : from ast import literal_eval def parses_to_integer(s): val = literal_eval(s) return isinstance(val, int)

How to display a number with always 2 decimal points using BigDecimal?

喜你入骨 提交于 2019-11-28 09:39:57
I am using BigDecimal to get some price values. Requirement is something like this, what ever the value we fetch from database, the displayed valued should have 2 decimal points. Eg: fetched value is 1 - should be displayed as 1.00 fetched value is 1.7823 - should be displayed as 1.78 I am using setScale(2, BigDecimal.ROUND_HALF_UP) but still some places, if the data from DB is a whole number then the same is being displayed !! I mean if the value is 0 from DB its displayed as 0 only. I want that to be displayed as 0.00 Thanks BigDecimal is immutable, any operation on it including setScale(2,

python float got a colon after the decimal point after addition [closed]

元气小坏坏 提交于 2019-11-28 04:46:32
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . In my python program, I got two floating numbers -2901.0, -200.0 during some process. When I tried to add them directly I got -3100.: (If I converted it to str , it would be "-3100.:" ) Python didn't say any

How to calculate decimal digits of precision based on the number of bits?

我只是一个虾纸丫 提交于 2019-11-28 04:07:58
问题 I am learning about floating point formats (IEEE). In the single precision floating point format ,it is mentioned that the mantissa has 24 bits and so it has 6 1/2 decimal digits of precision (as the per the book "understanding the machine") , and 7.22 decimal digits of precision. I don't understand how the decimal digits of precision is calculated. Can somebody please enlighten me ? 回答1: With 24 bits, assuming one bit is reserved for the sign, then the largest decimal number you can

Limiting text field entry to only one decimal point

ⅰ亾dé卋堺 提交于 2019-11-27 18:37:55
问题 I have created a text field to enter an amount of money. I want the user to be able to enter only one decimal point. I implemented that in the -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string method. In the general case it works fine, but if backspace is pressed and the single decimal point is deleted, after that it still assumes that a decimal point has been entered, and so does not accept the decimal point again. I

Matlab: How to read in numbers with a comma as decimal separator?

…衆ロ難τιáo~ 提交于 2019-11-27 15:46:48
I have a whole lot (hundreds of thousands) of rather large (>0.5MB) files, where data are numerical, but with a comma as decimal separator. It's impractical for me to use an external tool like sed "s/,/./g" . When the separator is a dot, I just use textscan(fid, '%f%f%f') , but I see no option to change the decimal separator. How can I read such a file in an efficient manner? Sample line from a file: 5,040000 18,040000 -0,030000 Note: There is a similar question for R , but I use Matlab. With a test script I've found a factor of less than 1.5. My code would look like: tmco = {'NumHeaderLines',

How can I set the decimal separator to be a comma?

不问归期 提交于 2019-11-27 14:09:12
I would like to read and write pi as 3,141592 instead of 3.141592 , as using the comma is common in many European countries. How can I accomplish this with iostream s? In other words cout << 3.141592; should print 3,141592 to standard output. You should use basic_ios::imbue to set the preferred locale. Take a look here: http://www.cplusplus.com/reference/ios/ios_base/imbue/ Locales allow you to use the preferred way by the user, so if a computer in Italy uses comma to separate decimal digits, in the US the dot is still used. Using locales is a Good Practice. But if you want to explicitly force

Simplest way of getting the number of decimals in a number in JavaScript [duplicate]

落爺英雄遲暮 提交于 2019-11-27 13:31:28
问题 This question already has an answer here: Is there a reliable way in JavaScript to obtain the number of decimal places of an arbitrary number? 7 answers Is there a better way of figuring out the number of decimals on a number than in my example? var nbr = 37.435.45; var decimals = (nbr!=Math.floor(nbr))?(nbr.toString()).split('.')[1].length:0; By better I mean faster to execute and/or using a native JavaScript function, ie. something like nbr.getDecimals(). Thanks in advance! EDIT: After