-
-
Save hanipcode/f1a6b172c37187e5d41b735f14db5278 to your computer and use it in GitHub Desktop.
Curr with K M B T
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
const SI_SYMBOL = ["", "k", "M", "G", "T", "P", "E"]; | |
function abbreviateNumber(number){ | |
const tier = Math.log10(number) / 3 | 0; | |
if(tier == 0) return number; | |
const suffix = SI_SYMBOL[tier]; | |
const scale = Math.pow(10, tier * 3); | |
const scaled = number / scale; | |
return [scaled.toFixed(1), suffix]; | |
} | |
const Curr = ({ number }) => { | |
const [value, suffix] = abbreviateNumber(number); | |
return ( | |
<> | |
<Currency value={value} /> | |
{suffix} | |
</> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment