0

I want to print currency symbol from its currency code.
but it not working from variable.

My Code:-

render() {
  var currencyCode = "$"
  return (
      <View>
        <Text>{currencyCode}</Text>
        <Text>&#36;</Text>
      </View>
  )
}

Output:- enter image description here

if enter static currency code so it is working but not working from variable.

How to print currency symbol from variable?

4
  • 1
    Possible duplicate of React app rendering html entities such as ampersand as escaped Commented Oct 9, 2018 at 8:25
  • above link for webpage but i'm using react native mobile application Commented Oct 9, 2018 at 8:31
  • See Render HTML in React Native Commented Oct 9, 2018 at 8:36
  • The answer in dupe question explains all options. There are three of them. If you can't use dangerouslysetinnerhtml in React Native then you have only two. Commented Oct 9, 2018 at 8:40

2 Answers 2

1

This similar question explains all available options. Since dangerouslySetInnerHTML is inapplicable in React Native, there are only two of them.

HTML entities can be specifically decoded, e.g. with html-entities:

import { Html5Entities } from 'html-entities';
const htmlEntities = new Html5Entities();

...

{htmlEntities.decode(htmlString)}

The problem can be avoided by not storing HTML entities in the first place if possible. Currency symbols are valid Unicode characters and can be stored as such:

var currencyCode = "€"; // &#8364;
Sign up to request clarification or add additional context in comments.

Comments

0

Think you should use unicoded symbols as shown in this tutorial

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.