/* * Testing unum_getDoubleAttribute and unum_setDoubleAttribute() */ static void TestDoubleAttribute(void) { double mydata[] = { 1.11, 22.22, 333.33, 4444.44, 55555.55, 666666.66, 7777777.77, 88888888.88, 999999999.99}; double dvalue; int i; UErrorCode status=U_ZERO_ERROR; UNumberFormatAttribute attr; UNumberFormatStyle style= UNUM_DEFAULT; UNumberFormat *def; log_verbose("\nTesting get and set DoubleAttributes\n"); def=unum_open(style, NULL,0,NULL,NULL, &status); if (U_FAILURE(status)) { log_data_err("Fail: error creating a default number formatter -> %s (Are you missing data?)\n", u_errorName(status)); } else { attr=UNUM_ROUNDING_INCREMENT; dvalue=unum_getDoubleAttribute(def, attr); for (i = 0; i<9 ; i++) { dvalue = mydata[i]; unum_setDoubleAttribute(def, attr, dvalue); if(unum_getDoubleAttribute(def,attr)!=mydata[i]) log_err("Fail: error in setting and getting double attributes for UNUM_ROUNDING_INCREMENT\n"); else log_verbose("Pass: setting and getting double attributes for UNUM_ROUNDING_INCREMENT works fine\n"); } } unum_close(def); }
static Variant HHVM_METHOD(NumberFormatter, getAttribute, int64_t attr) { NUMFMT_GET(obj, this_, false); switch (attr) { case UNUM(PARSE_INT_ONLY): case UNUM(GROUPING_USED): case UNUM(DECIMAL_ALWAYS_SHOWN): case UNUM(MAX_INTEGER_DIGITS): case UNUM(MIN_INTEGER_DIGITS): case UNUM(INTEGER_DIGITS): case UNUM(MAX_FRACTION_DIGITS): case UNUM(MIN_FRACTION_DIGITS): case UNUM(FRACTION_DIGITS): case UNUM(MULTIPLIER): case UNUM(GROUPING_SIZE): case UNUM(ROUNDING_MODE): case UNUM(FORMAT_WIDTH): case UNUM(PADDING_POSITION): case UNUM(SECONDARY_GROUPING_SIZE): case UNUM(SIGNIFICANT_DIGITS_USED): case UNUM(MIN_SIGNIFICANT_DIGITS): case UNUM(MAX_SIGNIFICANT_DIGITS): case UNUM(LENIENT_PARSE): { int64_t lval = unum_getAttribute(obj->formatter(), (UNumberFormatAttribute)attr); if (lval == -1) { obj->setError(U_UNSUPPORTED_ERROR); return false; } return lval; } case UNUM(ROUNDING_INCREMENT): { double dval = unum_getDoubleAttribute(obj->formatter(), (UNumberFormatAttribute)attr); if (dval == -1) { obj->setError(U_UNSUPPORTED_ERROR); return false; } return dval; } default: obj->setError(U_UNSUPPORTED_ERROR); return false; } }