Commit ba239065 by Nguyễn Thị Thúy

format money

parent e29604ca
......@@ -234,6 +234,17 @@ export const toPriceVnd = (str) => {
}
};
export const floatToPriceVnd = (str) => {
if (str) {
let stringPrice = str.toString().split('.')
let headStringPrice = `${stringPrice[0].replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,')}`
return stringPrice.length === 1 ? headStringPrice : headStringPrice.concat(`.${stringPrice[1]}`)
} else {
return ''
}
}
// cắt chuỗi dạng something...
export const ellipsis = (str = '', max = 30) =>
str.length > max ? `${str.substring(0, max)}...` : str;
......
......@@ -5,7 +5,7 @@ import HeaderBack from '../../components/Header/HeaderBack';
import PickerItem from '../../components/Picker/PickerItem';
import I18n from '../../helper/i18/i18n';
import AppText from '../../components/AppText';
import {getFontXD, HEIGHTXD, toPriceVnd, WIDTHXD} from '../../Config/Functions';
import {floatToPriceVnd, getFontXD, HEIGHTXD, toPriceVnd, WIDTHXD} from '../../Config/Functions';
import R from '../../assets/R';
import {getUnitList} from '../../apis/Functions/Transaction';
import {showAlert, TYPE} from '../../components/DropdownAlert';
......@@ -71,16 +71,12 @@ const ConvertUnit = (props) => {
const onChangeToUnit = (value, item) => {
setToUnit(item);
if (number && number != '' && parseFloat(number) > 0) {
let result = parseFloat(number) * item.rate;
setResult(`${parseFloat(number)} ${fromUnit.name} = ${result} ${item.name}`);
}
};
const calcultorResult = () => {
if (number && number != '' && parseFloat(number) > 0) {
let result = parseFloat(number) * toUnit.rate;
setResult(`${parseFloat(number)} ${fromUnit.name} = ${result} ${toUnit.name}`);
setResult(`${floatToPriceVnd(number.toString())} ${fromUnit.name} = ${floatToPriceVnd(result.toString())} ${toUnit.name}`);
} else {
setResult('')
}
......@@ -98,7 +94,7 @@ const ConvertUnit = (props) => {
keyboardType={'number-pad'}
style={styles.wrapInput}
maxLength={12}
value={toPriceVnd(number)}
value={floatToPriceVnd(number)}
/>
</View>
</View>
......@@ -179,6 +175,7 @@ const styles = StyleSheet.create({
fontSize: getFontXD(42),
borderRadius: 5,
paddingHorizontal: 10,
paddingVertical: 0,
shadowColor: '#000',
shadowOffset: {
width: 0,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment