numbers

Show more digits in PHP

左心房为你撑大大i 提交于 2019-12-01 22:32:45
问题 Let's say I have: echo 1/3; And it print out only 0.33333333333333, can I get more digits? 回答1: Can use bcdiv echo bcdiv(1, 3, 20); The third argument is used to set the number of digits after the decimal place in the result. You can also set the global default scale for all functions by using bcscale(). 回答2: Edit the precision configuration variable either in your php.ini or some other configuration location or use ini_set(). ini_set('precision', 22); echo 1/3; // 0.3333333333333333148296

Check if variable is number: Applescript

江枫思渺然 提交于 2019-12-01 22:17:29
How can I check if a variable is a number? I'm trying this: set a to 5 if a is a number display dialog "Yes! It's a number!" end if I've also tried this code: set a to 5 if a is integer display dialog "Yes! It's a number!" end if But unfortunately it doesn't work as expected. class of a is integer will fail if you use set a to "5" This will work if even if the variable is a number but was entered as text. set a to "5" try set a to a as number display dialog "Yes! It's a number!" end try set a to 5 if class of a is integer then display dialog "Yes! It's a number!" end if Mike Woodfill This is

Removing nonnumerical data out of a number + SQL

≡放荡痞女 提交于 2019-12-01 22:06:47
问题 I'm trying find the best way to remove nonnumerical data from a varchar in SQL e.g. '(082) 000-0000' to '0820000000' or '+2782 000 0000' to '0820000000' The difficulty is i'm not always sure what number formats are coming in, as shown above, so I'd like like everything that is not a number removed essentially. Update: From what you guys have said this is a little spike done: declare @Num varchar(20) set @Num = ' + (82) 468 6152 ' --strip nonnumrical data out of @num print @Num set @Num =

How to create a magic square in PHP?

◇◆丶佛笑我妖孽 提交于 2019-12-01 22:00:55
问题 I'd like to try my hand at creating a Magic Square in PHP (i.e. a grid of numbers that all add up to the same value), but I really don't know where to start. I know of the many methods that create magic square, such as starting "1" at a fixed position, then moving in a specific direction with each iteration. But that doesn't create a truly randomized Magic Square, which is what I'm aiming for. I want to be able to generate an N-by-N Magic Square of N² numbers where each row and column adds up

Removing nonnumerical data out of a number + SQL

二次信任 提交于 2019-12-01 21:56:52
I'm trying find the best way to remove nonnumerical data from a varchar in SQL e.g. '(082) 000-0000' to '0820000000' or '+2782 000 0000' to '0820000000' The difficulty is i'm not always sure what number formats are coming in, as shown above, so I'd like like everything that is not a number removed essentially. Update: From what you guys have said this is a little spike done: declare @Num varchar(20) set @Num = ' + (82) 468 6152 ' --strip nonnumrical data out of @num print @Num set @Num = replace(@Num, ' ', '') set @Num = replace(@Num, '+', '') set @Num = replace(@Num, '-', '') set @Num =

Convert numbers to words with VBA

旧巷老猫 提交于 2019-12-01 21:49:47
I have a column of numbers. In the next column, I want the text/word conversion of the numbers. Example : 123.561 would convert to One hundred twenty three point five six one . I do not want to convert to currency, just number to text, with any number of decimal places. How can I do this? ashleedawg Edit: I've adapted the procedure below to non-currency, unlimited decimal places. Edit 2 considers internationalisation via two changes in (1) Function SpellNumber and (2) Function fractionWords to make code work with other decimal separators (e.g. colon in middle Europe) ' - see comment Example:

Get a list of numbers from range(s) of number

倖福魔咒の 提交于 2019-12-01 21:37:16
I have a data frame where one column contains a range (or ranges) of numbers. I would like to turn this into a list of numbers based of the given range. Example input: "35-40" or "35-43, 45-47" This should yield: [1] 35 36 37 38 39 40 and [1] 35 36 37 38 39 40 41 42 43 45 46 47 We can do a split and with Map , get the numbers do.call(Map, c(`:`, lapply(strsplit(df1$v1, '-'), as.numeric))) #[[1]] # [1] 35 36 37 38 39 40 41 42 43 44 45 #[[2]] #[1] 43 44 45 46 47 If we need to find the sequence within the string lapply(strsplit(df1$v1, "-"), function(x) Reduce(`:`, as.numeric(x))) #[1]] #[1] 35

How to create a magic square in PHP?

本秂侑毒 提交于 2019-12-01 21:11:06
I'd like to try my hand at creating a Magic Square in PHP (i.e. a grid of numbers that all add up to the same value), but I really don't know where to start. I know of the many methods that create magic square, such as starting "1" at a fixed position, then moving in a specific direction with each iteration. But that doesn't create a truly randomized Magic Square, which is what I'm aiming for. I want to be able to generate an N-by-N Magic Square of N² numbers where each row and column adds up to N(N²+1)/2 (e.g. a 5x5 square where all rows/columns add up to 65 — the diagonals don't matter). Can

Convert Hexadecimal to String

一世执手 提交于 2019-12-01 21:08:41
To convert String to Hexadecimal i am using: public String toHex(String arg) { return String.format("%040x", new BigInteger(1, arg.getBytes("UTF-8"))); } This is outlined in the top-voted answer here: Converting A String To Hexadecimal In Java How do i do the reverse i.e Hexadecimal to String? You can reconstruct bytes[] from the converted string, here's one way to do it: public String fromHex(String hex) throws UnsupportedEncodingException { hex = hex.replaceAll("^(00)+", ""); byte[] bytes = new byte[hex.length() / 2]; for (int i = 0; i < hex.length(); i += 2) { bytes[i / 2] = (byte) (

Show more digits in PHP

安稳与你 提交于 2019-12-01 20:46:30
Let's say I have: echo 1/3; And it print out only 0.33333333333333, can I get more digits? Gordon Can use bcdiv echo bcdiv(1, 3, 20); The third argument is used to set the number of digits after the decimal place in the result. You can also set the global default scale for all functions by using bcscale(). Edit the precision configuration variable either in your php.ini or some other configuration location or use ini_set() . ini_set('precision', 22); echo 1/3; // 0.3333333333333333148296 Even though I highly doubt that you really need that kind of precision ;-) EDIT As Gordon said: you'll hit