numbers

a simple function for return number from string in php

痞子三分冷 提交于 2019-12-01 08:20:44
问题 I want capture Rank from this code : $RankStr = 'var trafficstatsSnippet = "/site/trafficstats;pysa1bpbPOVl6Wm5d4Zv4nKXKdM%3D /aahoonet.com/?adult=&category=&rank=1234567";' I use this code : $NewPOS = strpos($RankStr, "rank="); $SRank = substr($RankStr, $NewPOS + 5, 10); echo $SRank; because of RANK code variable from (1 - 25,000,000) , i use above code by selecting maximum 10 charachters after starting position of rank= plus 5 further index. so this function return 1234567"; and after that

Floating point number representation, Java example [duplicate]

南笙酒味 提交于 2019-12-01 08:12:01
This question already has an answer here: Is floating point math broken? 31 answers Could you please explain, why I got next result: when I run this: System.out.println((0.2 - 0.1)); I got: 0.1 when I run this: System.out.println((0.3 - 0.2)); I got: 0.09999999999999998 I know that number "0.1" doesn't have finite representation in binary, but it doesn't explain the results above. Most likely this is not about particular language but about how digits are stored in computer. Java uses IEEE floating point to represent double values. It is not a precise representation, and some calculations

Sorting divs by number inside div tag and jQuery

余生颓废 提交于 2019-12-01 07:55:33
I'm trying to sort a list of divs with jQuery. Essentially the list might look like this: <div class="contest_entry"><img src="image.png" /><span class="votes">14</span></div> <div class="contest_entry"><img src="image.png" /><span class="votes">8</span></div> <div class="contest_entry"><img src="image.png" /><span class="votes">2</span></div> <div class="contest_entry"><img src="image.png" /><span class="votes">2</span></div> <div class="contest_entry"><img src="image.png" /><span class="votes">2</span></div> <div class="contest_entry"><img src="image.png" /><span class="votes">21</span></div

What is the most efficient way to find amicable numbers in python?

自作多情 提交于 2019-12-01 07:14:15
问题 I've written code in Python to calculate sum of amicable numbers below 10000: def amicable(a, b): total = 0 result = 0 for i in range(1, a): if a % i == 0: total += i for j in range(1, b): if b % j == 0: result += j if total == b and result == a: return True return False sum_of_amicables = 0 for m in range (1, 10001): for n in range (1, 10001): if amicable(m, n) == True and m != n: sum_of_amicables = sum_of_amicables + m + n Code is running more than 20 minutes in Python 2.7.11. Is it ok? How

Is there a way to round a decimal place to the nearest whole in javascript?

喜欢而已 提交于 2019-12-01 06:52:55
I have a number with decimal places and I am wondering if it's possible to round the decimal to the nearest whole using javascript? My number is: 4.59 I need my number to round to: 4.60 Use Number.toFixed(number of decimal places) : var num = 4.59; var rounded = num.toFixed(1); Jakub Konecki Use the toFixed() method. More detailed information at: MDN :: toFixed var x = 4.5678; Math.round(x * 10) / 10; // 4.6 Math.round(x * 100) / 100; // 4.57 Where the number of 0 s of multiplication and division is the decimal point you are aiming for. I propose you do what Daff suggests, but if you want the

Converting two Uint32Array values to Javascript number

♀尐吖头ヾ 提交于 2019-12-01 06:49:27
I found a code from here that converts Javascript number to inner IEEE representation as two Uint32 values: function DoubleToIEEE(f) { var buf = new ArrayBuffer(8); (new Float64Array(buf))[0] = f; return [ (new Uint32Array(buf))[0] ,(new Uint32Array(buf))[1] ]; } How to convert the returned value back to Javascript number? This way: var number = -10.3245535; var ieee = DoubleToIEEE(number) var number_again = IEEEtoDouble(ieee); // number and number_again should be the same (if ever possible) That code is ugly as hell. Use function DoubleToIEEE(f) { var buf = new ArrayBuffer(8); var float = new

Convert float number to string with engineering notation (with SI prefix) in Python

回眸只為那壹抹淺笑 提交于 2019-12-01 06:27:00
I have a float number such as x=23392342.1 I would like to convert it to a string with engineering notation (with metric prefix) http://en.wikipedia.org/wiki/Engineering_notation http://en.wikipedia.org/wiki/Metric_prefix So in my example 23392342.1 = 23.3923421E6 = 23.3923421 M (mega) I would like to display 23.3923421 M Here is a function inspired from Formatting a number with a metric prefix? metric.py #!/usr/bin/env python # -*- coding: utf-8 -*- import math def to_si(d, sep=' '): """ Convert number to string with SI prefix :Example: >>> to_si(2500.0) '2.5 k' >>> to_si(2.3E6) '2.3 M' >>>

Thymeleaf对象的使用:数字对象

女生的网名这么多〃 提交于 2019-12-01 06:15:48
Thymeleaf主要使用 org.thymeleaf.expression.Numbers 类处理数字,在模板中使用 #numbers 对象来处理数字。 开发环境:IntelliJ IDEA 2019.2.2 Spring Boot版本:2.1.8 新建一个名称为demo的Spring Boot项目。 pom.xml加入Thymeleaf依赖: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> 一、整数格式化 有4个方法: (1)formatInteger(number,digits) 第一个参数为单个数字,如果有小数字点则四舍五入,第二个参数设置最少的整数位数,不足会补0(下同) (2)arrayFormatInteger(numbers,digits) 传入数组,返回处理后的数组 (3)listFormatInteger(numbers,digits) 传入List,返回处理后的List (4)setFormatInteger(numbers,digits) 传入Set,返回处理后的Set 这4个方法存在重载方法传入第三个参数,用于标识千位分隔符 POINT : 使用“.”

Representation of a Kilo/Mega/Tera Byte

拥有回忆 提交于 2019-12-01 06:07:38
I was getting a little confused with the representation of different units of bytes. It is accepted throughout that 1 byte = 8 bits. However, in a lot of sources I have seen that 1 kiloByte = 2^10 bytes = 1024 bytes AND 1 kiloByte = 1000 bytes Doesn't this contradict as in both cases it is stated that 1 byte is 8 bits...? Different sources claim different reasons for these different representations, thus I am not sure what the most important/real reason is for this rather confusing difference in representation. Can someone please explain and clarify? It is accepted throughout that 1 byte = 8

How to display the leading zero's in a number of oracle

送分小仙女□ 提交于 2019-12-01 05:40:42
I have an oracle column(artnr) contains a length of 1 which is of type number(9). I want to update the number as following... Example : If number is 0 then it should be 00000 If number is 1 then it should be 00001 If number is 12 the it should be 00012 Remember : here 00000,0000, and 00012 are of number datatypes The following are the methods I have tried but failed.. UPDATE pitb.toestel b SET b.artnr = LPAD (b.artnr, 5, 0) WHERE b.idinventaris = 403743; Failed because Lpad can only be applied on strings UPDATE pitb.toestel b SET b.artnr = TO_NUMBER (TO_CHAR (artnr, '00009'), '00009') WHERE b