NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package jp.co.vinculumjapan.mdware.common.util;

import java.math.BigDecimal;
import java.math.BigInteger;

/**
* <p>�^�C�g��: CalcUtility(�v�Z���[�e�B���e�B�N���X)</p>
* <p>����: �v�Z�������s�����[�e�B���e�B�N���X�����B</p>
* <p>������: Copyright (c) 2008</p>
* <p>������: Vinculum Japan Corporation</p>
* @author VJC
* @version 1.00
*/
public class CalcUtility {

/** �G���[�������p�l */
private static String NUM_ERROR_RET = "0";
/** �����v�Z�l */
private static String PARSENT_VAL = "100";

/**
* �����Z���s�����<br>
* @param val �����f�[�^
* @param addVal �����f�[�^�����Z�����l
* @return �����Z����
*/
public static String plus(String val, String addVal) {

String result = "";

try {
// �����Z���s
BigDecimal bdVal = new BigDecimal(isNumNull(val));
BigDecimal bdAddVal = new BigDecimal(isNumNull(addVal));
result = bdVal.add(bdAddVal).toString();
} catch (Exception e) {
// ���O���������A�u0�v���p
return NUM_ERROR_RET;
}

return result;
}

/**
* �����Z���s�����<br>
* @param val �����f�[�^
* @param minusVal �����f�[�^�����Z�����l
* @return �����Z����
*/
public static String minus(String val, String minusVal) {

String result = "";

try {
// �����Z���s
BigDecimal bdVal = new BigDecimal(isNumNull(val));
BigDecimal bdMinusVal = new BigDecimal(isNumNull(minusVal));
result = bdVal.subtract(bdMinusVal).toString();
} catch (Exception e) {
// ���O���������A�u0�v���p
return NUM_ERROR_RET;
}

return result;
}

/**
* �|���Z���s�����<br>
* @param val �����f�[�^
* @param mVal �����f�[�^�����Z�����l
* @return �|���Z����
*/
public static String multiply(String val, String mVal) {
return calcMultiply(val, mVal, 0, BigDecimal.ROUND_UNNECESSARY);
}

/**
* �|���Z�i�l�������p�j���s�����<br>
* �w�������������A�[�������i�l�������j���s���B<br>
* @param val �����f�[�^
* @param mVal �����f�[�^�����Z�����l
* @param scale �����_��������
* @return �|���Z�����i�����F�l�������j
*/
public static String multiplyRound(String val, String mVal, int scale) {
return calcMultiply(val, mVal, scale, BigDecimal.ROUND_HALF_UP);
}

/**
* �|���Z�i���������p�j���s�����<br>
* �w�������������A�[�������i���������j���s���B<br>
* @param val �����f�[�^
* @param mVal �����f�[�^�����Z�����l
* @param scale �����_��������
* @return �|���Z�����i�����F���������j
*/
public static String multiplyRoundUp(String val, String mVal, int scale) {
return calcMultiply(val, mVal, scale, BigDecimal.ROUND_UP);
}

/**
* �|���Z�i���������p�j���s�����<br>
* �w�������������A�[�������i���������j���s���B<br>
* @param val �����f�[�^
* @param mVal �����f�[�^�����Z�����l
* @param scale �����_��������
* @return �|���Z�����i�����F���������j
*/
public static String multiplyRoundDown(String val, String mVal, int scale) {
return calcMultiply(val, mVal, scale, BigDecimal.ROUND_DOWN);
}

/**
* �����Z�i�l�������p�j���s�����<br>
* �w�������������A�[�������i�l�������j���s���B<br>
* @param val �����f�[�^
* @param dVal �����f�[�^�����Z�����l
* @param scale �����_��������
* @return �����Z�����i�����F�l�������j
*/
public static String divideRound(String val, String dVal, int scale) {
return calcDivide(val, dVal, scale, BigDecimal.ROUND_HALF_UP);
}

/**
* �����Z�i���������p�j���s�����<br>
* �w�������������A�[�������i���������j���s���B<br>
* @param val �����f�[�^
* @param dVal �����f�[�^�����Z�����l
* @param scale �����_��������
* @return �����Z�����i�����F���������j
*/
public static String divideRoundUp(String val, String dVal, int scale) {
return calcDivide(val, dVal, scale, BigDecimal.ROUND_UP);
}

/**
* �����Z�i���������p�j���s�����<br>
* �w�������������A�[�������i���������j���s���B<br>
* @param val �����f�[�^
* @param dVal �����f�[�^�����Z�����l
* @param scale �����_��������
* @return �����Z�����i�����F���������j
*/
public static String divideRoundDown(String val, String dVal, int scale) {
return calcDivide(val, dVal, scale, BigDecimal.ROUND_DOWN);
}

/**
* �����v�Z�i�l�������p�j���s�����<br>
* �����f�[�^�����Z�����l�����Z���A�w�������������A�[�������i�l�������j���s���B<br>
* �[��������100�����Z���A�����l���Z�o�����B<br>
* @param val �����f�[�^
* @param dVal �����f�[�^�����Z�����l
* @param scale �����_��������
* @return �����v�Z�����i�����F�l�������j
*/
public static String parsentRound(String val, String dVal, int scale) {
// �����Z���s(�l������)
String result = calcDivide(val, dVal, (scale + 2), BigDecimal.ROUND_HALF_UP);
// �p�[�Z���g�v�Z���s(100�|���Z)
result = calcMultiply(result, PARSENT_VAL, 0, BigDecimal.ROUND_UNNECESSARY);
// �v�Z�������e�������l(�����E����)�`�F�b�N�����s���A���p
return checkLimitValue(result, scale);
}

/**
* �����v�Z�i���������p�j���s�����<br>
* �����f�[�^�����Z�����l�����Z���A�w�������������A�[�������i���������j���s���B<br>
* �[��������100�����Z���A�����l���Z�o�����B<br>
* @param val �����f�[�^
* @param dVal �����f�[�^�����Z�����l
* @param scale �����_��������
* @return �����v�Z�����i�����F���������j
*/
public static String parsentRoundUp(String val, String dVal, int scale) {
// �����Z���s(�l������)
String result = calcDivide(val, dVal, (scale + 2), BigDecimal.ROUND_UP);
// �p�[�Z���g�v�Z���s(100�|���Z)
result = calcMultiply(result, PARSENT_VAL, 0, BigDecimal.ROUND_UNNECESSARY);
// �v�Z�������e�������l(�����E����)�`�F�b�N�����s���A���p
return checkLimitValue(result, scale);
}

/**
* �����v�Z�i���������p�j���s�����<br>
* �����f�[�^�����Z�����l�����Z���A�w�������������A�[�������i���������j���s���B<br>
* �[��������100�����Z���A�����l���Z�o�����B<br>
* @param val �����f�[�^
* @param dVal �����f�[�^�����Z�����l
* @param scale �����_��������
* @return �����v�Z�i�����F���������j
*/
public static String parsentRoundDown(String val, String dVal, int scale) {
// �����Z���s(�l������)
String result = calcDivide(val, dVal, (scale + 2), BigDecimal.ROUND_DOWN);
// �p�[�Z���g�v�Z���s(100�|���Z)
result = calcMultiply(result, PARSENT_VAL, 0, BigDecimal.ROUND_UNNECESSARY);
// �v�Z�������e�������l(�����E����)�`�F�b�N�����s���A���p
return checkLimitValue(result, scale);
}

/**
* ���l��������Null�����������������A0������ <br>
*
* @param val �f�[�^
* @return ����
*/
private static String isNumNull(String val) {

// �������Anull ���������������������������A�u0�v���p
if (val == null || val.trim().length() == 0) {
val = NUM_ERROR_RET;
}

return val;
}

/**
* �|���Z���v�Z���������s�������<br>
* @param val �����f�[�^
* @param mVal �����f�[�^�����Z�����l
* @param scale �����_��������
* @param roundingMode �������[�h�w���l
* @return �|���Z����
*/
private static String calcMultiply(String val, String mVal, int scale,
int roundingMode) {

String result = "";

try {
// �|���Z���s
BigDecimal bdVal = new BigDecimal(isNumNull(val));
BigDecimal bdMVal = new BigDecimal(isNumNull(mVal));
if (roundingMode == BigDecimal.ROUND_UNNECESSARY) {
// �����A�����_�w���K�v����
result = bdVal.multiply(bdMVal).toString();
} else {
// �����A�����_�w���K�v�L
result = bdVal.multiply(bdMVal).setScale(scale, roundingMode).toString();
}
} catch (Exception e) {
// ���O���������A�u0�v���p
BigDecimal err = new BigDecimal(new BigInteger(NUM_ERROR_RET), scale);
return err.toString();
}

return result;
}

/**
* �����Z���v�Z���������s�������<br>
* @param val �����f�[�^
* @param dVal �����f�[�^�����Z�����l
* @param scale �����_��������
* @param roundingMode �������[�h�w���l
* @return �����Z����
*/
private static String calcDivide(String val, String dVal, int scale,
int roundingMode) {

String result = "";

try {
// �����Z���s
BigDecimal bdVal = new BigDecimal(isNumNull(val));
BigDecimal bdDVal = new BigDecimal(isNumNull(dVal));
result = bdVal.divide(bdDVal, scale, roundingMode).toString();
} catch (Exception e) {
// ���O���������A�u0�v���p
BigDecimal err = new BigDecimal(new BigInteger(NUM_ERROR_RET), scale);
return err.toString();
}

return result;
}

/**
* �����l�`�F�b�N���s�����<br>
* �������d�l���������������������l(�����E����)�����������������`�F�b�N���A������
* �����������A�d�l�����l���l���������A�����l���������p����<br>
* @param checkVal �`�F�b�N�����l
* @param scale �����_��������
* @return �`�F�b�N�������l������
*/
private static String checkLimitValue(String checkVal, int scale) {

String result = "";

try {
BigDecimal bdCheckVal = new BigDecimal(isNumNull(checkVal));

// (�����������K�v�����������v����)
// (�������K�v���������A�����d�l���m�����A���e�m��)
// (2008.12.18 �����F1000%������999.9... -1000%������-999.9... ������)
if (bdCheckVal.compareTo(new BigDecimal(1000)) >= 0) {
// 1000%����������999.9...����������
String ika = "";
if (scale > 0) {
ika = ".";
}
for (int i = 0 ; i < scale ; i++) {
ika += "9";
}
bdCheckVal = new BigDecimal("999" + ika);
} else if(bdCheckVal.compareTo(new BigDecimal(-1000)) <= 0) {
// -1000%����������-999.9...����������
String ika = "";
if (scale > 0) {
ika = ".";
}
for (int i = 0; i < scale; i++) {
ika += "9";
}
bdCheckVal = new BigDecimal("-999" + ika);
} else {
// �����K�v�������������Ascale����
bdCheckVal.setScale(scale);
}

// scale����
BigDecimal sca = bdCheckVal.setScale(scale);
result = sca.toString();
} catch (Exception e) {
// ���O���������A�u0�v���p
BigDecimal err = new BigDecimal(new BigInteger(NUM_ERROR_RET), scale);
return err.toString();
}

return result;
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.