問題描述,輸入兩個整數a, b,將分數輸出a/b的小數格式,如果a/b是迴圈小數,則將迴圈部分用括號括起來,例如:
1/4 = 0.25; 1/3=0.(3); 1/6=0.1(6);
分析:實質上是實現高精度浮點數除法。借助雜湊表來獲取迴圈部分。
public class solution {
static int b = integer.size - 1;
public static string fractiontodecimal(int numerator, int denominator) {
stringbuffer res = new stringbuffer();
long remainder = numerator;
long der = denominator;
remainder = math.abs(remainder);
der = math.abs(der);
remainder%=der; remainder*=10;
if(remainder==0) return res.tostring();
else{
//快取表,用於搜尋迴圈位
hashmaptab = new hashmap();
while(!tab.containskey(remainder) && remainder>0){
while(remainder
Java 金額小數轉換成中文大寫金額
參照nndhyp的部落格。財務系統應用較多 將金額小數轉換成中文大寫金額 如40330701101.2 肆佰零叄億叄千零柒拾萬壹千壹佰零壹元貳角 如下 金額小數轉換成中文大寫金額 author neil han public class convertmoneytouppercase private...
漢字轉換成拼音
c 乙個有用的漢字轉拼音類 c 漢字轉換為拼音的類,含大小寫轉換 因為是靜態函式 呼叫方法很簡單 crazycoderpinyin.convert 瘋狂 如下 using system using system.collections.generic using system.text using ...
數字轉換成漢字
我們通過追加的方式來實現,考慮到我們的數字是四四分組的,所以我們要先實現四位數正確轉換,上述問題解決之後,再列印四位以上數字時,我們就可以通過追加的方式解決五位以上數 萬 字的追加,同時此程式只能對千萬級別以內的數字進行轉換。public class test02 else if i percent...