How can I put the text "100.000" in a table in Anychart? When I try to get the string "100.000" in, it is modified to "100".
For a working example see https://jsfiddle.net/Republiq/xcemvm9L/
table = anychart.standalones.table(2,2);
table.getCell(0,0).content("100.000");
table.container("container").draw();
If you want to use such number formatting for the whole table you can define numberLocale in the beginning. If the actual number is 100 and '.' - is a decimal separator and you want to show 3 zeros as decimals, put the following lines before creating the table:
anychart.format.locales.default.numberLocale.decimalsCount = 3;
anychart.format.locales.default.numberLocale.zeroFillDecimals = true;
And then put in the number as:
table.getCell(0,0).content(100);
If '.' - is a group separator and the actual number is 100000, put the following line:
anychart.format.locales.default.numberLocale.groupsSeparator = '.';
And then put in the number as:
table.getCell(0,0).content(100000);
If you want to use special format only for a single cell, we recommend you to use number formatter, which helps to configure all these options only for a single number. For example, it may looks like:
table = anychart.standalones.table(5,5);
table.getCell(0,0).content(anychart.format.number(100000, 3, ".", ","));
table.container("container").draw();
Also, you may learn more about this useful method and find examples in this article
Related
I have a giftcardamounts in database table.
Column contains dollar and comma separated values.
There are 40 rows.
Ex:
row 1: giftcardamounts : ($10,$20,$30,$40,$50)
row 2: giftcardamounts : ($100,$200,$30,$40,$50)
row 3: giftcardamounts : ($10,$20,$300,$400,$500)
...etc
From frontend there is an input is giftcardselectedamount
Ex: giftcardselectedamount=500
Based on this input amount in need to write LINQ query on dollar and comma separated list of Values.
Please help me how to write this.
Like commenters have noted, you should show some effort in reaching to an answer. Also your question isn't quite clear. Are you asking to return the row with a matching amount? If so you can try the following approach, which returns the first row that contains the dollar amount specified:
void Main()
{
var data = new[] {
"$10,$20,$30,$40,$50",
"$100,$200,$30,$40,$50",
"$10,$20,$300,$400,$500"};
var giftcardSelectedAmount = 500M;
var matchingRow = data.FirstOrDefault(x => x
.Split(',')
.Any(v => decimal.Parse(v, NumberStyles.Currency) == giftcardSelectedAmount));
Console.WriteLine(matchingRow);
}
I can easily modify this answer to return all matching rows, a count of occurrences, or a count of rows with occurrences. Let me know if you need any of these modifications and I can modify my answer to add these.
I would like to check if a specific column in one of my tables meets the following conditions:
String must contain at least three characters
String must contain at least two different numbers [e.g. 123 would work but 111 would not]
Characters which are allowed in the string:
Numbers (0-9)
Uppercase letters
Lowercase letters
Underscores (_)]
Dashes (-)
I have some experience with Regex but am having issues with Snowflake's syntax. Whenever I try using the '?' regex character (to mark something as optional) I receive an error. Can someone help me understand a workaround and provide a solution?
What I have so far:
SELECT string,
LENGTH(string) AS length
FROM tbl
WHERE REGEXP_LIKE(string,'^[0-9]+{3,}[-+]?[A-Z]?[a-z]?$')
ORDER BY length;
Thanks!
Your regex looks a little confusing and invalid, and it doesn't look like it quite meets your needs either. I read this expression as a string that:
Must start with one or more digits, at least 3 or more times
The confusing part to me is the '+' is a quantifier, which is not quantifiable with {3,} but somehow doesn't produce an error for me
Optionally followed by either a dash or plus sign
Followed by an uppercase character zero or one times (giving back as needed)
Followed by and ending with a lowercase character zero or one times (giving back as needed)
Questions
You say that your string must contain 3 characters and at least 2 different numbers, numbers are characters but I'm not sure if you mean 3 letters...
Are you considering the numbers to be characters?
Does the order of the characters matter?
Can you provide an example of the error you are receiving?
Notes
Checking for a second digit that is not the same as the first involves the concept of a lookahead with a backreference. Snowflake does not support backreferences.
One thing about pattern matching with regular expressions is that order makes a difference. If order is not of importance to you, then you'll have multiple patterns to match against.
Example
Below is how you can test each part of your requirements individually. I've included a few regexp_substr functions to show how extraction can work to check if something exists again.
Uncomment the WHERE clause to see the dataset filtered. The filters are written as expressions so you can remove any/all of the regexp_* columns.
select randstr(36,random(123)) as r_string
,length(r_string) AS length
,regexp_like(r_string,'^[0-9]+{3,}[-+]?[A-Z]?[a-z]?$') as reg
,regexp_like(r_string,'.*[A-Za-z]{3,}.*') as has_3_consecutive_letters
,regexp_like(r_string,'.*\\d+.*\\d+.*') as has_2_digits
,regexp_substr(r_string,'(\\d)',1,1) as first_digit
,regexp_substr(r_string,'(\\d)',1,2) as second_digit
,first_digit <> second_digit as digits_1st_not_equal_2nd
,not(regexp_instr(r_string,regexp_substr(r_string,'(\\d)',1,1),1,2)) as first_digit_does_not_appear_again
,has_3_consecutive_letters and has_2_digits and first_digit_does_not_appear_again as test
from table(generator(rowcount => 10))
//where regexp_like(r_string,'.*[A-Za-z]{3,}.*') // has_3_consecutive_letters
// and regexp_like(r_string,'.*\\d+.*\\d+.*') // has_2_digits
// and not(regexp_instr(r_string,regexp_substr(r_string,'(\\d)',1,1),1,2)) // first_digit_does_not_appear_again
;
Assuming the digits need to be contiguous, you can use a javascript UDF to find the number in a string with with the largest number of distinct digits:
create or replace function f(S text)
returns float
language javascript
returns null on null input
as
$$
const m = S.match(/\d+/g)
if (!m) return 0
const lengths = m.map(m=> [...new Set (m.split(''))].length)
const max_length = lengths.reduce((a,b) => Math.max(a,b))
return max_length
$$
;
Combined with WHERE-clause, this does what you want, I believe:
select column1, f(column1) max_length
from t
where max_length>1 and length(column1)>2 and column1 rlike '[\\w\\d-]+';
Yielding:
COLUMN1 | MAX_LENGTH
------------------------+-----------
abc123def567ghi1111_123 | 3
123 | 3
111222 | 2
Assuming this input:
create or replace table t as
select * from values ('abc123def567ghi1111_123'), ('xyz111asdf'), ('123'), ('111222'), ('abc 111111111 abc'), ('12'), ('asdf'), ('123 456'), (null);
The function is even simpler if the digits don't have to be contiguous (i.e. count the distinct digits in a string). Then core logic changes to:
const m = S.match(/\d/g)
if (!m) return 0
const length = [...new Set (m)].length
return length
Hope that's helpful!
I want all data from column "A" to single-cell "d5" with comma-separated.
Example:
I have the following data in a sheet.
A1=john
A2=berry
A3=spartan
A4=sparrow
result i need is "john,berry,spartan,sparrow" in cell "d5".
Also, it would be great if I can set the desired no of rows instead of all.
like if required one than = "john" and
if required three than = "john,berry,spartan"
try like this:
=TEXTJOIN(","; 1; A:A)
for 3 use:
=TEXTJOIN(","; 1; A1:A3)
I have a cell array called BodyData in MATLAB that has around 139 columns and 3500 odd rows of skeletal tracking data.
I need to extract all rows between two string values (these are timestamps when an event happened) that I have
e.g.
BodyData{}=
Column 1 2 3
'10:15:15.332' 'BASE05' ...
...
'10:17:33:230' 'BASE05' ...
The two timestamps should match a value in the array but might also be within a few ms of those in the array e.g.
TimeStamp1 = '10:15:15.560'
TimeStamp2 = '10:17:33.233'
I have several questions!
How can I return an array for all the data between the two string values plus or minus a small threshold of say .100ms?
Also can I also add another condition to say that all str values in column2 must also be the same, otherwise ignore? For example, only return the timestamps between A and B only if 'BASE02'
Many thanks,
The best approach to the first part of your problem is probably to change from strings to numeric date values. In Matlab this can be done quite painlessly with datenum.
For the second part you can just use logical indexing... this is were you put a condition (i.e. that second columns is BASE02) within the indexing expression.
A self-contained example:
% some example data:
BodyData = {'10:15:15.332', 'BASE05', 'foo';...
'10:15:16.332', 'BASE02', 'bar';...
'10:15:17.332', 'BASE05', 'foo';...
'10:15:18.332', 'BASE02', 'foo';...
'10:15:19.332', 'BASE05', 'bar'};
% create column vector of numeric times, and define start/end times
dateValues = datenum(BodyData(:, 1), 'HH:MM:SS.FFF');
startTime = datenum('10:15:16.100', 'HH:MM:SS.FFF');
endTime = datenum('10:15:18.500', 'HH:MM:SS.FFF');
% select data in range, and where second column is 'BASE02'
BodyData(dateValues > startTime & dateValues < endTime & strcmp(BodyData(:, 2), 'BASE02'), :)
Returns:
ans =
'10:15:16.332' 'BASE02' 'bar'
'10:15:18.332' 'BASE02' 'foo'
References: datenum manual page, matlab help page on logical indexing.
I need to extract ICD 9 values from a requirements document. The ICD 9 values could be individual codes like V91.19 or ranges 441.00-441. For example:
4. Peripheral vascular disorders - ICD-9-CM codes: 440.0-440.9, 441.00-441.9, 442.0-442.9, 443.1-443.9, 447.1, 557.1, 557.9, V43.4, V91.19, V9000, V91, M8440/0
Ultimately, the goal is to use these values in a WHERE clause:
SELECT *
FROM ICD9
WHERE (
(CODE BETWEEN '440.0' AND '440.9')
OR (CODE BETWEEN '441.00' AND '441.9')
...
OR CODE IN ('447.1', '557.1', '557.9', 'V43.4', 'V91.19', 'V9000', 'V91', 'M8440/0')
)
This regex:
/[A-Z]?[0-9]+[\.\/]?[0-9]*/g
matches:
the individual ICD 9 values (447.1)
the starting and ending values of the range (440.0-440.9)
4. and ICD-9-CM - not desirable
How do I need to modify my regex to:
create a capture group for the individual values?
create a capture group for the range values?
exclude the undesirables?
Do you mean like this?
[A-Z]?[0-9]+[\.\/]?(?=\d)[0-9]*
where
(?=\d) The positive lookahead - Assert that the regex can be matched only if a digit [0-9]
Same results is if your remove the optional * part of the last digit like and replace it with +:
[A-Z]?[0-9]+[\.\/]?[0-9]+
https://regex101.com/r/nK3zB3/2
About the ranges and groups I think it could something like:
(([A-Z]?[0-9]+[\.\/]?[0-9]+)[-]*(([A-Z]?[0-9]+[\.\/]?[0-9]+))?)
Online Demo