float and double are two data type which is used to store floating point values in Java and we often need to convert String to float in Java and sometime even a Float object or float primitive to String. One thing, which is worth remembering about floating point numbers in Java is that they are approximate values, a float value 100.1f may hold actual value as 100.099998, which will be clear, when we seen examples of converting float to String and vice-versa. By the way, It's easy to parse String to float and vice-versa, as rich Java API provides several ways of doing it. If you already familiar with converting String to int or may be String to double in Java, then you can extend same techniques and method to parse float String values. key methods like valueOf() and parseInt(), which is used to parse String to float are overloaded for most primitive data types. If you are particularly interested on rounding of float values, you can use RoundingMode and BigDecimal class, as float and double are always approximate values and comparing two float variable of same values may not always return true, that's why it's advised, not to use float for monetary calculation. In this Java tutorial, we will first see examples of parsing String to float in Java and later converting float to String objects. Remember, we will use float and Float, a wrapper class corresponding to float primitive, interchangeably because by using Java 1.5 autoboxing feature, they are automatically converted to each other, without any Java code. For those, who are still in Java 1.4 or lower version, then can use Float.floatValue() to convert Float wrapper object to float primitive.
Read more »
Tampilkan postingan dengan label examples. Tampilkan semua postingan
Tampilkan postingan dengan label examples. Tampilkan semua postingan
10 examples of Date command in Unix
Diposting oleh
pebel
Kamis, 13 Februari 2014
di 01.00 0 komentar Label: 10, command, date, examples, in, of, unixDate command in unix or Linux is one of important command to learn and master because we always need date information. no matter you want to know current date in unix or your bash script needs current date in unix for archiving purpose you need to use date command. In its simplest format date command shows the current date and time in unix while with sophisticated option we can extract many useful information from unix date command. In this Unix command tutorial we will see some useful tips on using date command in unix and learn more around date in unix and Linux. One important thing to note is that different implementation of unix date command may not be exactly same e.g. AIX version of date command doesn't support option "-d" or "date". Anyway let's see some example of unix date command:
By the way this is fifth article in my series of covering examples of important and frequently used commands e.g. find examples, grep examples, chmod example and sort command example.
Langganan:
Postingan (Atom)