sign "+" before positive values on axis - google-visualization

I am trying to format data on value axes google chart:
=> sign "+" before positives values
=> sign "-" before negatives values
ex: -2 -1 0 +1 +2 ...
Maybe with options format? Any ideas?

Use the vAxis.format option. The format option takes an ICU number pattern, which separates out positive and negative formats with a semicolon, so you could have, as an example:
vAxis: {
format: '+#;-#'
}
which would format 3 as "+3" and -7 as "-7".

Related

Remove Zeros Before Decimal- PowerBI

Numbers under 1 are currently being represented with a leading zero before the decimal point (example: 0.50). Because I'm working with baseball statistics (which almost never have the zero before the decimal) I would like to remove that. I want to keep the number before the decimal if its greater than 1 though. How would I do that?
For instance if I'm working with this measure. Is there something I can add to that?
AVG = SUM(Batter[H])/sum(Batter[AB])
Thanks. I appreciate the help.
Here is some sample data
Name AB H
Gleyber Torres 546 152
Brett Gardner 491 123
Aaron Judge 378 103
Adam Ottavino 0 0
Aroldis Chapman 0 0
The NAN error is occurring because you are dividing by 0. You should add an IF condition to avoid that:
AVG = IF(sum(Batter[AB])=0,BLANK(),SUM(Batter[H])/sum(Batter[AB]))
To tackle the formatting issue you can use the FORMAT function as mentioned by Andrey:
AVG = IF(sum(Batter[AB])=0,BLANK(),FORMAT(SUM(Batter[H])/sum(Batter[AB]),"###.0#"))
Hope this helps.
Unfortunately, it isn't directly possible. However, in the last step (the visualization of the data), you can convert the decimal number to text and format it as you want. For example, your measure could be like this:
AVG = FORMAT(SUM(Batter[H])/SUM(Batter[AB]), "#,###.00")
This will give you 2 decimal places (0 means that there will be a digit displayed at this position), but the digits before the decimal are optional (# means it will show a digit, but will omit the leading zeros) or here are some examples:

Extract Number from String Field, Including Decimal (Postgres 9.5)

Suppose I have a field:
product_strength
10MG/ML
0.25MG
25MG
0.125MG
How do I extract just the "numeric" part and then cast to numeric? I can get this far: regexp_replace(product_strength, '(\D|!\.)','','g')::numeric AS result_numeric
But the problem with this is that it doesn't actually account for the decimal. In other words, this returns
product_strength result_numeric
10MG/ML 10
0.25MG 25
25MG 25
0.125MG 125
But I would want to return
product_strength result_numeric
10MG/ML 10
0.25MG 0.25
25MG 25
0.125MG 0.125
I would use regexp_matches for this:
select (regexp_matches(product_strength, '[0-9]+\.?[0-9]*'))[1]::numeric
from the_table
regexp_matches() returns an array of all matched strings, that's why the [1] is needed.
Try this regex to match the numbers;
\d+\.?\d*
Edit: as "Boolean_Type" says, if you need negative numbers too, you could add in an optional negative sign, and use;
\-?\d+\.?\d*

extract integer by digit position Swift

I have several pickerViews throughout the app where users input data. Later, I will display this data as a "summary" page. Displaying the data is clearly easy. However, if the user wants to "edit" the data, I want the same digits to load in the pickerView.
There will be case of 4 digits, 3 digits, 2 digits and a single digit.
So, I need to have the ability to determine which digit is in which position, if there is a digit.
So, if the integer is 321, how to get "1" as the first digit, "2" as the second digit and "3" as the third digit.
Thank you
myPicker.selectRow(row, inComponent: 0, animated: true)
You replace your row and 0 with your values. Then to get the numbers, only thing on my mind now would be something like
while number > 0 {
let digit = number%10 // do what you want with the digit
number = round(number/10)
}

Regex Numerical Range 1 - 1 million

I'm looking for a expression range for monetary purposes. It needs to be 1 - 1 million and allow commas and periods. I don't need a min/max of (, and .) for correct formatting but I would like the digits after a period to be a min/max of 2 for actual cent values. Thanks
In Range:
640 or 5,000.35 or 999,000
Not in Range:
01 or 1,000,000.01 or 333,567.678
What I would suggest is :
Use something like that to verify that the input has a specific format :
(here's a demo - http://regexr.com?30l28)
(1[\.,])?([0-9]{1,3}[\.,])?([0-9]{1,3})([\.,][0-9]{1,2})
And then test the value range :
is value<1.000.000?
My regex is by no means 100% complete, but it DOES verify your general number format though.
This should do it:
^(1(\.\d{2})?|[1-9]\d{0,2}(,?\d{3})?(\.\d{2})?)|1((,000){0,2}|(000){0,2})(\.00)?$
But it would probably easier if you normalize the value first (e. g. remove any character except digits and the .) and then parse it.

Regex that matches integers in between whitespace or start/end of string only

I'm currently using the pattern: \b\d+\b, testing it with these entries:
numb3r
2
3454
3.214
test
I only want it to catch 2, and 3454. It works great for catching number words, except that the boundary flags (\b) include "." as consideration as a separate word. I tried excluding the period, but had troubles writing the pattern.
Basically I want to remove integer words, and just them alone.
All you want is the below regex:
^\d+$
Similar to manojlds but includes the optional negative/positive numbers:
var regex = /^[-+]?\d+$/;
EDIT
If you don't want to allow zeros in the front (023 becomes invalid), you could write it this way:
var regex = /^[-+]?[1-9]\d*$/;
EDIT 2
As #DmitriyLezhnev pointed out, if you want to allow the number 0 to be valid by itself but still invalid when in front of other numbers (example: 0 is valid, but 023 is invalid). Then you could use
var regex = /^([+-]?[1-9]\d*|0)$/
You could use lookaround instead if all you want to match is whitespace:
(?<=\s|^)\d+(?=\s|$)
This just allow positive integers.
^[0-9]*[1-9][0-9]*$
I would add this as a comment to the other good answers, but I need more reputation to do so. Be sure to allow for scientific notation if necessary, i.e. 3e4 = 30000. This is default behavior in many languages. I found the following regex to work:
/^[-+]?\d+([Ee][+-]?\d+)?$/;
// ^^ If 'e' is present to denote exp notation, get it
// ^^^^^ along with optional sign of exponent
// ^^^ and the exponent itself
// ^ ^^ The entire exponent expression is optional
This solution matches integers:
Negative integers are matched (-1,-2,etc)
Single zeroes are matched (0)
Negative zeroes are not (-0, -01, -02)
Empty spaces are not matched ('')
/^(0|-*[1-9]+[0-9]*)$/
^([+-]?[0-9]\d*|0)$
will accept numbers with leading "+", leading "-" and leadings "0"
Try /^(?:-?[1-9]\d*$)|(?:^0)$/.
It matches positive, negative numbers as well as zeros.
It doesn't match input like 00, -0, +0, -00, +00, 01.
Online testing available at http://rubular.com/r/FlnXVL6SOq
^(-+)?[1-9][0-9]*$
starts with a - or + for 0 or 1 times, then you want a non zero number (because there is not such a thing -0 or +0) and then it continues with any number from 0 to 9
This worked in my case where I needed positive and negative integers that should NOT include zero-starting numbers like 01258 but should of course include 0
^(-?[1-9]+\d*)$|^0$
Example of valid values:
"3",
"-3",
"0",
"-555",
"945465464654"
Example of not valid values:
"0.0",
"1.0",
"0.7",
"690.7",
"0.0001",
"a",
"",
" ",
".",
"-",
"001",
"00.2",
"000.5",
".3",
"3.",
" -1",
"+100",
"--1",
"-.1",
"-0",
"00099",
"099"