Skip to Content

Convert java Double to numeric primitive data types example

  • strict warning: Non-static method view::load() should not be called statically in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/views.module on line 906.
  • strict warning: Declaration of views_handler_argument::init() should be compatible with views_handler::init(&$view, $options) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_argument.inc on line 0.
  • strict warning: Declaration of views_handler_filter::options_validate() should be compatible with views_handler::options_validate($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter.inc on line 0.
  • strict warning: Declaration of views_handler_filter::options_submit() should be compatible with views_handler::options_submit($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter.inc on line 0.
  • strict warning: Declaration of views_handler_filter_boolean_operator::value_validate() should be compatible with views_handler_filter::value_validate($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter_boolean_operator.inc on line 0.
  • strict warning: Declaration of views_plugin_style_default::options() should be compatible with views_object::options() in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_style_default.inc on line 0.
  • strict warning: Declaration of views_plugin_row::options_validate() should be compatible with views_plugin::options_validate(&$form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_row.inc on line 0.
  • strict warning: Declaration of views_plugin_row::options_submit() should be compatible with views_plugin::options_submit(&$form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_row.inc on line 0.

  1. /*
  2.   Convert Double to numeric primitive data types example
  3.   This example shows how a Double object can be converted into below given numeric
  4.   primitive data types
  5.   - Convert Double to byte
  6.   - Convert Double to short
  7.   - Convert Double to int
  8.   - Convert Double to float
  9.   - Convert Double to double
  10. */
  11.  
  12. public class JavaDoubleToNumericPrimitiveTypesExample {
  13.  
  14.   public static void main(String[] args) {
  15.  
  16.     Double dObj = new Double("10.50");
  17.     //use byteValue method of Double class to convert it into byte type.
  18.     byte b = dObj.byteValue();
  19.     System.out.println(b);
  20.    
  21.     //use shortValue method of Double class to convert it into short type.
  22.     short s = dObj.shortValue();
  23.     System.out.println(s);
  24.    
  25.     //use intValue method of Double class to convert it into int type.
  26.     int i = dObj.intValue();
  27.     System.out.println(i);
  28.    
  29.     //use floatValue method of Double class to convert it into float type.
  30.     float f = dObj.floatValue();
  31.     System.out.println(f);
  32.  
  33.     //use doubleValue method of Double class to convert it into double type.
  34.     double d = dObj.doubleValue();
  35.     System.out.println(d);
  36.  
  37.   }
  38. }
  39.  
  40. /*
  41. Output of the program would be :
  42. 10
  43. 10
  44. 10
  45. 10.5
  46. 10.5
  47. */