简体   繁体   中英

How to connect special symbols like   ¥ in react-native

I want connect a string use " ` " , and wish " & yen; " will show as "¥", the code like below :

let str=`${period} per (money:¥${money})`

but did not work for me ,

by the way,I write it use react-native

To parse HTML Entities you can use the npm module html-entities .

Here is a working example:

import { Html5Entities } from 'html-entities'; 

render() {
    const entities = new Html5Entities();
    return (
      <SafeAreaView style={styles.container}>
        <View>
        <Text> {entities.decode('&yen')} </Text>
        </View>
      </SafeAreaView>
    );
  }

Output:

输出示例

you can use javascript native method like

let formattedMoney = new Intl.NumberFormat('ja-JP', { style: 'currency', currency: 'JPY' }).format(money);
let str=`${period} per (money:${formattedMoney})`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM