Wednesday, September 7, 2011

Java : Using currency format

// Using currency notations i.e. Colombian Currency
public String FormateoValor(Double valor){
NumberFormat n = NumberFormat.getCurrencyInstance(new Locale("es", "CO")); 
String returnString = n.format(valor.doubleValue());
return returnString ;  
}


References:
http://www.javaworld.com/javaworld/jw-06-2001/jw-0601-cents.html
http://www.herongyang.com/JDK/Locale-java-util-Local-Localization.html

Tuesday, September 6, 2011

Java: convert String to Long and vice versa

// String to long
long l = Long.parseLong(str);

// long to string
String numCadena= String.valueOf(l);

Sources:
http://www.java-tips.org/java-se-tips/java.lang/conversion-from-string-to-long.html
http://www.java-examples.com/java-string-valueof-example

Java: convert String to int and vice versa


// string to int
int numEntero = Integer.parseInt(numCadena);

// int to String
String numCadena= String.valueOf(numEntero);

Source:
http://emilio.aesinformatica.com/2007/11/22/pasar-de-int-a-string-y-de-string-a-int-en-java/

Sunday, September 4, 2011

Python : add days, hours, minutes to datetime

newDate = datetime.datetime.now() +timedelta(days=10,hours=23,minutes=15)

Reference:
http://www.daniweb.com/software-development/python/threads/192860

Excel 2007: Switch Columns and Rows



1. Open the spreadsheet you need to change.
2. If needed, insert a blank worksheet.
3. Click the first cell of your data range such as A1.
4. Shift-click the last cell of the range. Your selection should highlight.
5. From the Edit menu, select Copy.
6. At the bottom of the page, click the tab for the blank worksheet such as Sheet2.
7. In the blank worksheet, click cell A1.
8. From the Edit menu, select Paste Special. The Paste Special dialog should appear.
9. Click the checkbox for Transpose.
10. Click OK.


Source:
http://www.timeatlas.com/5_minute_tips/general/how_to_switch_excel_columns_and_rows

Monday, August 29, 2011

MS SQL: query to add column

ALTER TABLE {TABLENAME}
ADD {COLUMNNAME} {TYPE} {NULL|NOT NULL}
CONSTRAINT {CONSTRAINT_NAME} DEFAULT {DEFAULT_VALUE}

i.e:

ALTER TABLE Protocols ADD ProtocolTypeID int NOT NULL DEFAULT(1);

Friday, August 26, 2011

HTML DOM: Remove all items(childrens) from div

myDiv = document.getElementById('light');

while (myDiv.hasChildNodes()) {
    myDiv.removeChild(myDiv.lastChild);
}

Reference: