Decimal
Code IndexAdd Codota to your IDE (free)

Best code snippets using org.hl7.fhir.utilities.ucum.Decimal(Showing top 15 results out of 315)

origin: jamesagnew/hapi-fhir

public Decimal divInt(Decimal other) throws UcumException  {
 if (other == null)
   return null;
 Decimal t = divide(other);
 return t.trunc();
}
origin: jamesagnew/hapi-fhir

 private void testSubtract(String s1, String s2, String s3) throws UcumException  {
  Decimal v1 = new Decimal(s1);
  Decimal v2 = new Decimal(s2);
  Decimal v3 = v1.subtract(v2);
 check(v3.asDecimal().equals(s3), s1+" - "+s2+" = "+s3+", but the library returned "+v3.asDecimal());
}
  
origin: jamesagnew/hapi-fhir

public static Decimal one() {
  try {
    return new Decimal("1");
  } catch (Exception e) {
    return null; // won't happen
  }
}
origin: jamesagnew/hapi-fhir

 public int asInteger() throws UcumException  {
  if (!isWholeNumber())
   throw new UcumException("Unable to represent "+toString()+" as an integer");
  if (comparesTo(new Decimal(Integer.MIN_VALUE)) < 0)
    throw new UcumException("Unable to represent "+toString()+" as a signed 8 byte integer");
  if (comparesTo(new Decimal(Integer.MAX_VALUE)) > 0)
    throw new UcumException("Unable to represent "+toString()+" as a signed 8 byte integer");
  return Integer.parseInt(asDecimal());
}
origin: jamesagnew/hapi-fhir

public Decimal copy() {
  Decimal result = new Decimal();
  result.precision = precision;
  result.scientific = scientific;
  result.negative = negative;
  result.digits = digits;
  result.decimal = decimal;
  return result;
}
origin: jamesagnew/hapi-fhir

 @Override
public Pair getCanonicalForm(Pair value) throws UcumException  {
   assert value != null : paramError("getCanonicalForm", "value", "must not be null");
   assert checkStringParam(value.getCode()) : paramError("getCanonicalForm", "value.code", "must not be null or empty");
   
   Term term = new ExpressionParser(model).parse(value.getCode());
   Canonical c = new Converter(model, handlers).convert(term);
   if (value.getValue() == null)
     return new Pair(null, new ExpressionComposer().compose(c, false));
   else
     return new Pair(value.getValue().multiply(c.getValue()), new ExpressionComposer().compose(c, false));
 }
 
origin: jamesagnew/hapi-fhir

private int countSignificants(String value) {
  int i = value.indexOf(".");
  if (i > -1)
    value = delete(value, i, 1);
  while (value.charAt(0) == '0')
    value = value.substring(1);
  return value.length();
}
origin: jamesagnew/hapi-fhir

 private Decimal absolute() {
  Decimal d = copy();
  d.negative = false;
  return d;
}
origin: jamesagnew/hapi-fhir

public Decimal add(Decimal other) {
 if (other == null) 
  return null;
 
 if (negative == other.negative) {
  Decimal result = doAdd(other);
  result.negative = negative;
  return result;
 } else if (negative) 
  return other.doSubtract(this);
 else
   return doSubtract(other);
}
origin: jamesagnew/hapi-fhir

 private void testCompares(String v1, String v2, int outcome) throws UcumException  {
  Decimal d1 = new Decimal(v1);
  Decimal d2 = new Decimal(v2);
  int result = d1.comparesTo(d2);
  check(result == outcome, "Compare fail: "+v1+".compares("+v2+") should be "+Integer.toString(outcome)+" but was "+Integer.toString(result));	  
}
  
origin: jamesagnew/hapi-fhir

@Override
public Decimal getValue() {		
  try {
  return new Decimal(5).divide(new Decimal(9));
} catch (Exception e) {
  // won't happen
  return null;
}
}
origin: jamesagnew/hapi-fhir

 private void testDivide(String s1, String s2, String s3)  throws UcumException  {
  Decimal v1 = new Decimal(s1);
  Decimal v2 = new Decimal(s2);
  Decimal v3 = v1.divide(v2);
 check(v3.asDecimal().equals(s3), s1+" / "+s2+" = "+s3+", but the library returned "+v3.asDecimal());
}
origin: jamesagnew/hapi-fhir

 private void testMultiply(String s1, String s2, String s3) throws UcumException  {
  Decimal v1 = new Decimal(s1);
  Decimal v2 = new Decimal(s2);
  Decimal v3 = v1.multiply(v2);
 check(v3.asDecimal().equals(s3), s1+" * "+s2+" = "+s3+", but the library returned "+v3.asDecimal());
}
origin: jamesagnew/hapi-fhir

 private void testAdd(String s1, String s2, String s3) throws UcumException  {
  Decimal v1 = new Decimal(s1);
  Decimal v2 = new Decimal(s2);
  Decimal v3 = v1.add(v2);
 check(v3.asDecimal().equals(s3), s1+" + "+s2+" = "+s3+", but the library returned "+v3.asDecimal());
}
  
origin: jamesagnew/hapi-fhir

public static Decimal zero()  {
  try {
    return new Decimal("0");
  } catch (Exception e) {
    return null; // won't happen
  }
}
org.hl7.fhir.utilities.ucumDecimal

Javadoc

Precision aware Decimal implementation. Any size number with any number of significant digits is supported. Note that operations are precision aware operations. Note that whole numbers are assumed to have unlimited precision. For example: 2 x 2 = 4 2.0 x 2.0 = 4.0 2.00 x 2.0 = 4.0 and 10 / 3 = 3.33333333333333333333333333333333333333333333333 10.0 / 3 = 3.33 10.00 / 3 = 3.333 10.00 / 3.0 = 3.3 10 / 3.0 = 3.3 Addition 2 + 0.001 = 2.001 2.0 + 0.001 = 2.0 Note that the string representation is precision limited, but the internal representation is not. This class is defined to work around the limitations of Java Big Decimal

Most used methods

  • <init>
    There are a few circumstances where a simple value is known to be correct to a high precision. For i
  • asDecimal
  • divInt
  • divide
  • modulo
  • absolute
  • add
  • allZeros
  • asInteger
  • asScientific
  • cdig
  • comparesTo
  • cdig,
  • comparesTo,
  • copy,
  • countSignificants,
  • delete,
  • dig,
  • doAdd,
  • doSubtract,
  • format,
  • insert

Popular classes and methods

  • getApplicationContext (Context)
  • getOriginalFilename (MultipartFile)
  • getSupportFragmentManager (FragmentActivity)
  • Kernel (java.awt.image)
  • SocketException (java.net)
    This SocketException may be thrown during socket creation or setting options, and is the superclass
  • SocketTimeoutException (java.net)
    This exception is thrown when a timeout expired on a socket read or accept operation.
  • BitSet (java.util)
    This implementation uses bit groups of size 32 to keep track of when bits are set to true or false.
  • GregorianCalendar (java.util)
    GregorianCalendar is a concrete subclass of Calendarand provides the standard calendar used by most
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • Reference (javax.naming)

For IntelliJ IDEA,
Android Studio or Eclipse

  • Codota IntelliJ IDEA pluginCodota Android Studio pluginCode IndexSign in
  • EnterpriseFAQAboutContact Us
  • Terms of usePrivacy policyCodeboxFind Usages
Add Codota to your IDE (free)