Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/decimal2.0.0 #41

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void main() {
LogUtil.e("TimerTick: " + value.toString());
});
timerUtil.startTimer();
if (timerUtil != null) timerUtil.cancel(); //dispose()
timerUtil.cancel(); //dispose()

TimerUtil timerCountDown;
//倒计时test
Expand Down
26 changes: 13 additions & 13 deletions lib/src/json_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class JsonUtil {
static T? getObj<T>(String? source, T f(Map v)) {
if (source == null || source.isEmpty) return null;
try {
Map map = json.decode(source);
Map map = json.decode(source) as Map;
return f(map);
} catch (e) {
print('JsonUtil convert error, Exception:${e.toString()}');
Expand All @@ -32,9 +32,9 @@ class JsonUtil {
try {
Map map;
if (source is String) {
map = json.decode(source);
map = json.decode(source) as Map;
} else {
map = source;
map = source as Map;
}
return f(map);
} catch (e) {
Expand All @@ -47,12 +47,12 @@ class JsonUtil {
static List<T>? getObjList<T>(String? source, T f(Map v)) {
if (source == null || source.isEmpty) return null;
try {
List list = json.decode(source);
return list.map((value) {
List list = json.decode(source) as List;
return list.map((dynamic value) {
if (value is String) {
value = json.decode(value);
}
return f(value);
return f(value as Map);
}).toList();
} catch (e) {
print('JsonUtil convert error, Exception:${e.toString()}');
Expand All @@ -66,15 +66,15 @@ class JsonUtil {
try {
List list;
if (source is String) {
list = json.decode(source);
list = json.decode(source) as List;
} else {
list = source;
list = source as List;
}
return list.map((value) {
return list.map((dynamic value) {
if (value is String) {
value = json.decode(value);
}
return f(value);
return f(value as Map);
}).toList();
} catch (e) {
print('JsonUtil convert error, Exception:${e.toString()}');
Expand All @@ -88,11 +88,11 @@ class JsonUtil {
static List<T>? getList<T>(dynamic source) {
List? list;
if (source is String) {
list = json.decode(source);
list = json.decode(source) as List;
} else {
list = source;
list = source as List;
}
return list?.map((v) {
return list.map((dynamic v) {
return v as T;
}).toList();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/money_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class MoneyUtil {
/// yuan to fen.
/// 元 转 分,
static int changeY2F(Object yuan) {
return NumUtil.multiplyDecStr(yuan.toString(), '100').toInt();
return NumUtil.multiplyDecStr(yuan.toString(), '100').toBigInt().toInt();
}

/// with unit.
Expand Down
4 changes: 3 additions & 1 deletion lib/src/num_util.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:decimal/decimal.dart';
import 'package:rational/rational.dart';

/**
* @Author: Sky24n
Expand Down Expand Up @@ -131,7 +132,8 @@ class NumUtil {

/// 除
static Decimal divideDecStr(String a, String b) {
return Decimal.parse(a) / Decimal.parse(b);
Rational value = Decimal.parse(a) / Decimal.parse(b);
return value.toDecimal();
}

/// 余数
Expand Down