Samual Sam has Published 2492 Articles

Java Program to round a double passed to BigDecimal

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

280 Views

The java.math.BigDecimal class provides operations for arithmetic, scale manipulation, rounding, comparison, hashing, and format conversion.Firstly, let us pass a double to BigDecimal −BigDecimal val = new BigDecimal(9.19456);Now, we will round it −val = val.setScale(2, BigDecimal.ROUND_HALF_EVEN);Above, we have used the field ROUND_HALF_EVEN. It is a rounding mode to round towards the ... Read More

Create a BigDecimal via string in Java

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

170 Views

Let us see how we can create BigDecimal values via string. Here, we have set string as a parameter to the BigDecimal constructor.BigDecimal val1 = new BigDecimal("375789755.345778656"); BigDecimal val2 = new BigDecimal("525678755.155778656");We can also perform mathematical operations on it −val2 = val2.subtract(val1);The following is an example −Example Live Demoimport java.math.BigDecimal; public ... Read More

ftp_site() function in PHP

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

31 Views

The ftp_site() function sends an FTP SITE command to the FTP server.Syntaxftp_site(conn, command);Parametersconn − The FTP connectioncommand − The SITE command. These commands vary from server to server and used in handling OS specific features such as file permissions and group membership.ReturnThe ftp_site() function returns TRUE on success or FALSE ... Read More

Subtract one BigDecimal from another BigDecimal in Java

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

315 Views

Use the subtract method to subtract one BigDecimal to another in Java. TheBigDecimal.subtract(BigDecimal val) returns a BigDecimal whose value is (this - subtrahend), and whose scale is max(this.scale(), subtrahend.scale()). Here, “val” is the value to be subtracted from this BigDecimal.The following is an example −Example Live Demoimport java.math.BigDecimal; public class Demo ... Read More

Display seconds with SimpleDateFormat('ss') in Java

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

827 Views

To work with SimpleDateFormat class in Java, import the following package.import java.text.SimpleDateFormat;Now, set the format with SimpleDateFormat(“ss”) to display seconds in two-digit.Format f = new SimpleDateFormat(”ss”);Now, get the seconds in a string −String strSeconds = f.format(new Date());The following is an example −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; ... Read More

ftp_ssl_connect() function in PHP

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

229 Views

The ftp_ssl_connect() function opens a secure SSL-FTP connection.Syntaxftp_ssl_connect(host, port, timeout);Parametershost − The FTP server address. Can be a domain address or an IP address.port − The port to connect to. Here the default is 21.timeout − The timeout for network operations.ReturnThe ftp_ssl_connect() function returns a SSL-FTP stream on success or ... Read More

Display time zone with SimpleDateFormat(“z”) in Java

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

2K+ Views

You can display timezone easily in Java using SimpleDateFormat(“z”).Firstly, to work with SimpleDateFormat class in Java, import the following package −import java.text.SimpleDateFormat;Now, set the format with SimpleDateFormat(“z”) to display timezone −Format f = new SimpleDateFormat(”z”);Now, get the timezone in a string −String strTimeZone = f.format(new Date());The following is an example ... Read More

ftp_systype() function in PHP

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

36 Views

The ftp_systype() function returns the system type identifier of the FTP server.Syntaxftp_systype(con);Parameterscon − The FTP connectionReturnThe ftp_systype() function returns the system type on success, or FALSE on failure.ExampleThe following is an example −

Java Program to subtract long integers and check for overflow

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

630 Views

To check for Long overflow, we need to check the Long.MAX_VALUE with the subtracted long result. Here, Long.MAX_VALUE is the maximum value of Long type in Java.Let us see an example wherein long integers are subtracted and if the result is still more than the Long.MAX_VALUE, then an exception is ... Read More

Convert long primitive to Long object in Java

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

7K+ Views

To convert long primitive to Long object, follow the below steps.Let’s say the following is our long primitive.// primitive long val = 45; System.out.println("long primitive: "+val);Now, to convert it to Long object is not a tiresome task. Include the same long value while creating a new Long object −// object ... Read More

Advertisements