decimal-point

how can i show an irrational number to 100 decimal places in python?

五迷三道 提交于 2019-11-27 13:17:16
I am trying to find the square root of 2 to 100 decimal places, but it only shows to like 10 by default, how can I change this? decimal module comes in handy. >>> from decimal import * >>> getcontext().prec = 100 >>> Decimal(2).sqrt() Decimal('1.414213562373095048801688724209698078569671875376948073176679737990732478462107038850387534327641573') You can use the decimal module for arbitrary precision numbers: import decimal d2 = decimal.Decimal(2) # Add a context with an arbitrary precision of 100 dot100 = decimal.Context(prec=100) print d2.sqrt(dot100) If you need the same kind of ability

mysql trigger operand should contain 2 columns

空扰寡人 提交于 2019-11-27 08:45:02
问题 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

How to fix an application that has a problem with decimal separator

会有一股神秘感。 提交于 2019-11-27 06:11:19
问题 This post is about C# and .Net, but some info is valuable for other techonolgies. Since I can remember, I've been having problems with apps or games that crash because of a different style of parsing decimal numbers. It happens very often, from CAD apps, libraries to web pages. I'm not sure whether it is ignorance or lack of knowledge, but it's really annoying. What's the problem? Here is a wiki article about it, but it short: Here is a map that shows what kind of decimal separator (decimal

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

ぃ、小莉子 提交于 2019-11-27 03:54:13
问题 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? 回答1: 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 回答2: Python float objects have an is_integer

How to round a decimal for output?

心不动则不痛 提交于 2019-11-27 03:49:59
问题 Using C#, I want to format a decimal to only display two decimal places and then I will take that decimal and subtract it to another decimal. I would like to be able to do this without having to turn it into a string first to format and then convert it back to a decimal. I'm sorry I forget to specify this but I don't want to round, I just want to chop off the last decimal point. Is there a way to do this? 回答1: If you don't want to round the decimal, you can use Decimal.Truncate. Unfortunately

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

回眸只為那壹抹淺笑 提交于 2019-11-27 03:04:25
问题 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

Leave only two decimal places after the dot

感情迁移 提交于 2019-11-26 22:36:51
public void LoadAveragePingTime() { try { PingReply pingReply = pingClass.Send("logon.chronic-domination.com"); double AveragePing = (pingReply.RoundtripTime / 1.75); label4.Text = (AveragePing.ToString() + "ms"); } catch (Exception) { label4.Text = "Server is currently offline."; } } Currently my label4.Text get's something like: "187.371698712637". I need it to show something like: "187.37" Only two posts after the DOT. Can someone help me out? string.Format is your friend. String.Format("{0:0.00}", 123.4567); // "123.46" Anas If you want to take just two numbers after comma you can use the

In jQuery, what's the best way of formatting a number to 2 decimal places?

夙愿已清 提交于 2019-11-26 19:44:54
This is what I have right now: $("#number").val(parseFloat($("#number").val()).toFixed(2)); It looks messy to me. I don't think I'm chaining the functions correctly. Do I have to call it for each textbox, or can I create a separate function? If you're doing this to several fields, or doing it quite often, then perhaps a plugin is the answer. Here's the beginnings of a jQuery plugin that formats the value of a field to two decimal places. It is triggered by the onchange event of the field. You may want something different. <script type="text/javascript"> // mini jQuery plugin that formats to

Integer.valueOf() vs. Integer.parseInt() [duplicate]

≡放荡痞女 提交于 2019-11-26 19:24:14
This question already has an answer here: Difference between parseInt and valueOf in java? 12 answers Aside from Integer.parseInt() handling the minus sign (as documented), are there any other differences between Integer.valueOf() and Integer.parseInt() ? And since neither can parse , as a decimal thousands separator (produces NumberFormatException ), is there an already available Java method to do that? corsiKa Actually, valueOf uses parseInt internally. The difference is parseInt returns an int primitive while valueOf returns an Integer object. Consider from the Integer.class source: public

Change decimal separator in MySQL

▼魔方 西西 提交于 2019-11-26 17:48:15
Is it possible to change the decimal comma from "." (dot) to other character (comma) in MySQL output? I don't want to use functions like FORMAT , I just want to use all the queries I normaly use without any modification. I'm looking for some setting (of some variable, locale etc.). I tried to search the manual but without success. ypercubeᵀᴹ No, you can't. That's the SQL standard and MySQL complies with it (in that point at least). The problem is not really with output (as you mention, there are various FORMAT functions in most DBMSs) but with INSERT . If you could use comma , for example as