C# code to format amount value - c#-2.0

Here I have data in a dataset like below
EmpID Amount
100 890
200 4567.78
300 4578
Now I want C# code to format Amount column values like below
EmpID Amount
100 0890.00
200 4567.78
300 4578.00
Thanks
Anuradha.J

int amount = ????; // vale of the amount column
String.Format("{0:0000.00}", amount);

ok: this is it:
ToString("000000.00")

You can use .ToString(format) (if is a decimal or something like this).
More information here: http://msdn.microsoft.com/en-us/library/fzeeb5cd.aspx

Related

RUNNING TOTAL with ARRAYFORMULA that can SUM and SUBTRACT if cell values changes

I'm trying to calculate the cumulative total in a column. It needs to sum or subtract if the value of (A) cell is set to buy or sell. here is an example:
A (task)
B (qtty)
C (total)
calculation explanation
buy
10
10
sum 10
buy
10
20
sum 10
sell
5
15
subtract 5
buy
20
35
sum 20
sell
10
25
subtract 10
I´m using the folowing formula:
={"Total", ARRAYFORMULA(IF(LEN(A2:A),IF(A2:A="buy",SUMIF(ROW(B2:B),"<="&ROW(B2:B),B2:B), "NEED CODE FOR SELL" ),))}
Is there another way to do the calc?
I don't want to use negative values to subtract, because the values are used in other formulas.
Thanks in advance.
try this:
=SCAN(0,A2:A,LAMBDA(ac,cv,if(cv="",,ac + ifs(cv="buy",OFFSET(cv,,1),cv="sell",-OFFSET(cv,,1)))))
You can use SCAN:
=ArrayFormula(IFNA(SCAN(,A2:A&B2:B,LAMBDA(tot,cur,tot+REGEXEXTRACT(cur,"\d+")*IF(REGEXMATCH(cur,"(?i)buy"),1,-1)))))
Or:
=SCAN(,B2:B,LAMBDA(tot,cur,IF(cur,tot+IF(INDEX(A2:A,ROW(cur)-1)="buy",cur,-cur),)))
It's also possible to do it with Sumif:
=ArrayFormula(if(A2:A="",,
sumif(row(A2:A)*if(A2:A="buy",1,9^9),"<="&row(A2:A),B2:B)-
sumif(row(A2:A)*if(A2:A="sell",1,9^9),"<="&row(A2:A),B2:B)))
Of course, there's no particular reason for doing it this way now that you have lambdas. I'm including it for old time's sake as I was one of the first people to use Sumif in this way.

Multiplying Duration

I have a spreadsheet with, in one column a duration express using the following format:4:36. 4 minutes and 36 seconds. I would like to multiply it with a number representing the number of views on the video. For instance, the spreadsheet would look like this:
1876|4:36
What shall I put in the next cell to multiply the two, ultimately I would like to have the result in the format: "HH:mm:ss".
try:
=TEXT(((REGEXEXTRACT(TO_TEXT(B1), "^\d+")*60+
REGEXEXTRACT(TO_TEXT(B1), "\d+$"))*A1)/1440/60, "[h]:mm:ss")

query about Excel formula - function

I have an issue with excel, lets say someone purchased something in (A1)100 dollars and i have to cut (B1)4.5 % of the said amount as tax. then when i want to insert the remaining amount after the deduction of tax(C1) that is (A1)-(B1). it shows 96 dollars. but actually it should be 95 dollars.
Check the format of the cell that has the result (C1). Make sure it is number and has two decimal places.

Taking Average of Money in SQL/SQLPro

I am working on a dataset, and I am having trouble trying to calculate the average of a column with dollar currencies in it. All the values, for example, are listed in the format of $12.00, $5.43, $1,234.00.....
Whenever I use the code below, it returns a value of 0 as the avg. In the same vein, it does the same thing for the SUM command as well.
SELECT AVG(bill_amount) FROM Trips WHERE trip_date >= '08/13/13';
Is there something wrong with the code I am using, because I think it's right.
You would appear to be storing values in the bill_amount column as text rather than as a number. You can convert them to a number and then use average. Something like this:
select avg(cast(case when substr(bill_amount, 1, 1) between '0' and '9' then bill_amount
else substr(bill_amount, 2)
end) as decimal(18, 4))

How to trim the decimal part from money field

I have a View() with a link to make a payment. Link looks something like this
Pay Now
My problem is Model.Amount has the amount format like this 20.00 or 100.00 because the DataType is money and its adding extra zero's.
I need to remove the '.' so it reads 2000 or 10000.
How can I achieve that?

Resources