WIN A $100 HP GIFT CARD. JUST LEAVE A COMMENT AS AN ENTRY. CLICK THIS [LINK] FOR DETAILS.

Java Round Float Variable

A nifty tool to round off a float variable to the nearest decimal place.

public static float roundFloat(float f, int decimals) {
  String s = number2str((Double.valueOf(String.valueOf(f))).doubleValue(), decimals);
  Float ff = Float.valueOf(replaceString(s, ",", ""));
  return ff.floatValue();
}

Found this post useful? Buy me a cup of coffee or help support the sponsors on the right.


(1 votes, average: 5.00 out of 5)
 Loading ...

Line Break? Carriage Return?

Operating systems have different ways on treating on line break symbols. But what exactly is a carriage return? In some operating systems like Mac OS, carriage returns also have line breaks embedded with them. Carriage return means going to move the position of the cursor to the first position on the same line. In programming languages we often see this character \r. While a line break’s character is \n, other operating systems like Windows actually combine both \r\n to denote a next line (and a carriage return). Notice the ENTER key’s symbol on the keyboard? the direction is first going down, then the arrow points to left which indicates the cursor would be on the first position of the next line. Here is a list of 3 famous operating systems and how they handle line breaks.

Windows = \r\n
Unix = \n
Mac OS = \r

Found this post useful? Buy me a cup of coffee or help support the sponsors on the right.


(1 votes, average: 5.00 out of 5)
 Loading ...

Javascript Check If Object Is Valid

Checks if an object exists in the document using Javascript.

function isValidObject(objToTest) {
  if (null == objToTest) return false;
  if ("undefined" == typeof(objToTest)) return false;
  return true;
}

Found this post useful? Buy me a cup of coffee or help support the sponsors on the right.


(1 votes, average: 5.00 out of 5)
 Loading ...

Javascript Maximize Popup Window

I forgot where I got this from. If anyone knows who owns this code please let me know. It’s what I use to maximize a popup window. It doesn’t have the same effect as when you click on the maximize button of an application window. What it does is get the screen dimensions and uses those measurements to set the popup window’s width and height.

function maximizeWindow() {
  window.moveTo(0, 0);
  if (document.all) {
    top.window.resizeTo(screen.availWidth,screen.availHeight);
  } else if (document.layers||document.getElementById) {
    if (top.window.outerHeight < screen.availHeight || top.window.outerWidth < screen.availWidth) {
      top.window.outerHeight = screen.availHeight;
      top.window.outerWidth = screen.availWidth;
    }
  }
}

Found this post useful? Buy me a cup of coffee or help support the sponsors on the right.


(1 votes, average: 5.00 out of 5)
 Loading ...