I'd like to format a numeric columns as follow: "23400,34"
1) "," as decimal separator (if decimal is present).
2) no thousands separator.
I used this pattern "{0:#,##}"
This seems applyes "," as thousands separator
You can do it using the replace function, like so:
kendo.format("{0:0.00}", value).replace(".", ",")
Related
A data set like below:
07021201180934221NJL B2018 12X 15253 030C 000000.299
07021201180934231NSL B2018 12X 15253 030C 00000.014
07021201180941061NNL B2018 030C 000000.288
Questions are:
The characters in the first string "120118" means date "ddmmyy", how could I filter rows according to date characters using awk?
The characters in first string "NJL" or "NSL" or "NNL" means data type, what awk command to filter lines according to those three characters?
The third column could be some description like "12X 15253" or empty, how could I filter data out if the column is empty?
Thanks in advance!
this script has all the conditions
$ awk 'substr($1,5,6)==120118 && substr($1,length($1)-2)=="NNL" && $3$4==""' file
I am trying to change SQL*loader files to replace a comma in decimal numbers with a dot.
How the loader data file looks
Pamatstudijas,Lauksaimniecibas,4,16.01.2006,70,"5,38"
My control file
load data
infile 'C:\Users\Students\Documents\ricardshercbergs_itia\12\izmaksas1.dat'
into table kartoteka
fields terminated by "," Optionally Enclosed By '"'
TRAILING NULLCOLS
(stud_veids char,
fakultate char,
kurss Integer External,
izmaksas_datums date 'dd.mm.yyyy',
stipendija Integer External,
kompensacija "REPLACE (:kompensacija,',','.')" Decimal External ,
nauda_kopa ":stipendija+:kompensacija")
This: kompensacija "REPLACE (:kompensacija,',','.')" Decimal External , doesnt work as I expected. I get the error:
SQL*Loader-350: Syntax error at line 11.
Expecting "," or ")", found keyword decimal.
kompensacija "REPLACE (:kompensacija,',','.')" Decimal External ,
According to the example control file in the documentation the definition of the datatype comes before the transformation of the column, i.e. your spec should be:
kompensacija Decimal External "REPLACE (:kompensacija,',','.')"
It looks possible you're using REPLACE() to switch around what character is a decimal point and which is the thousands separator. If this is the case you can use TO_NUMBER, which makes it more obvious what you're doing and will fail with the correct error if the conversion is not possible:
kompensacija decimal external "to_number(:kompensacija, '99D99', 'NLS_NUMERIC_CHARACTERS = '',.''')"
I'm facing a strange issue where Cint and Cdbl are not returning expected output on Swedish keyboard. They work fine on English keyboard.
Cint("6.0") # Output: 60
Cdbl("70.8") # Output: 708
For some reason, both the functions are removing the decimal from string.
In VBA use Val, which always assume dot as decimal separator.
In VBScript, I use to solve this question using:
CDbl(Replace(number_in_string, ".", Mid(1.3, 2, 1)))
This way numeric 1.3 is converted into a localized string and decimal separator extracted from 2rd character. Then, dot in supplied string is replaced by decimal separator extracted.
Possible issues:
Thousand separators! If your number use thousand separators that are the same of your system decimal separator, convertion will get corrupt! Example: "1,234.56" will become "1,234,56"! Workaround:
CDbl(Replace(Replace(number_in_string, ",", ""), ".", Mid(1.3, 2, 1))) 'Remove comma thousand separator
Number formating: assuming 1.3 will become a string where decimal separator is in 2nd character is not acquired for sure!
I'm using Visual FoxPro and I need to convert currency amount into numeric. The 2 columns in the table are tranamt(numeric,12,2) and tranamt2(character)
Here's my example:
tranamt2=-$710,000.99
I've tried
replace all tranamt with val(tranamt2)
and
replace all tranamt with val(strtran(tranamt2, ",",""))
both results give me zero. I know it has something to do with the negative sign but I can't figure it out. Any help is appreciated.
Try this:
replace all tranamt with VAL(STRTRAN(STRTRAN(tranamt2, "$", ""), ",", ""))
This removes the dollar sign and comma in one shot.
need to convert currency amount into numeric
tranamt(numeric,12,2) and tranamt2(character)
First of all a neither a Character Field Type nor a Numeric Field type (tranamt2) are Not a VFP Currency Field type
You may be using the value of a Character field to represent currency, but that does not make it a currency value - just a String value.
And typically when that is done, you do NOT store the Dollar Sign '$' and Comma ',' as part of the data.
Instead, you store the 'raw' value (in this case: "-710000.99") and merely format how that 'raw' value is displayed when needed.
So in your Character field you have a value of: -$710,000.99
Do you have the Dollar Sign '$' and the Comma ',' as part of the field data?
If so, to convert it to a Numeric, you will first have to eliminate those extraneous characters prior to the the conversion.
If they are not stored as part of your field value, then you can use the VAL() 'as is'.
Example:
cStr = "-710000.99" && The '$' and ',' are NOT stored as part of Character value
nStr = VAL(cStr)
?nStr
However if you have the Dollar Sign and the Comma as part of the field data itself, then you can use STRTRAN() to eliminate them during the conversion.
Example:
cStr = "-$710,000.99" && Note both '$' and ',' are part of data value
* --- Remove both '$' and ',' and convert with VAL() ---
nStr = VAL(STRTRAN(STRTRAN(cStr,",",""),"$",""))
?nStr
Maybe something like:
REPLACE tranamt WITH VAL(STRTRAN(STRTRAN(tranamt2,",",""),"$",""))
EDIT: Another alternative would be to use CHRTRAN() to remove the '$' and ','
Something like:
cRemoveChar = "$," && Characters to be removed from String
REPLACE tranamt WITH VAL(CHRTRAN(tranamt2,cRemoveChar,""))
Good Luck
A little late but I use this function call
function MoneyToDecimal
LPARAMETER tnAmount
LOCAL lnAmount
IF VARTYPE(tnAmount) = "Y"
lnAmount = VAL(STRTRAN(TRANSFORM(tnAmount), "$", ""))
ELSE
lnAmount = tnAmount
ENDIF
return lnAmount
endfunc
And can be tested with these calls:
wait wind MoneyToDecimal($112.50)
wait wind MoneyToDecimal($-112.50)
Use the built-in MTON() function to convert a currency value into a numeric value:
replace all tranamt with mton(tranamt2)
I have a grid on a form that displays some columns from a dbf table and a textbox.
I want to search the value displayed in the textbox over all columns from a dbf table. Some fields are numeric and other are character
If I want to find a number, should search all record that contain that number in all columns, no matter the column type.
If I want to search a substring should give me all record that contain that substring.
SET FILTER TO ALLTRIM(ThisForm.Text1.Value) $Content or ALLTRIM(val(ThisForm.Text1.Value)) $registrationNumber or ALLTRIM(ThisForm.Text1.Value) $holderNo
Your approach with the "$" wildcard "contains" approach appears to be ok. However, your attempt via allt( val( )) would fail as you cant trim a numeric value, it would have to be pre-converted to a string.
Now, that said, you could shorten your query by just doing a $ against a concatenation of ALL columns something like (assuming your registration number is a numeric field)...
set filter to ALLTRIM(ThisForm.Text1.Value) ;
$ ( Content +"," +str(registrationNumber) +," + holderNo )
if you have dates or date/time fields you could do DTOC( dateField ) or TTOC( dateTimeField). So, by building a single string of all values, you dont have to explicitly repeat the OR condition repeatedly.
You could do something like:
select curGrid
scan
lcRow = transform(field1) + transform(field2) ... + transform(lastfield)
if lcSearchValue $ lcRow
DoWhatever()
endif
endscan
This leverages the fact that transform() will give a string representation of any data type.