How to use the @automattic/format-currency function in @automattic/format-currency

To help you get started, we’ve selected a few @automattic/format-currency examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Automattic / wp-calypso / client / extensions / woocommerce / woocommerce-services / views / shipping-label / label-purchase-modal / rates-step / index.js View on Github external
}

	const packageIds = Object.keys( selectedRates );

	// Show the service name and cost when only one service/package exists
	if ( 1 === packageIds.length ) {
		const packageId = packageIds[ 0 ];
		const selectedRate = selectedRates[ packageId ];
		const packageRates = get( availableRates, [ packageId, 'rates' ], [] );
		const rateInfo = find( packageRates, [ 'service_id', selectedRate ] );

		if ( rateInfo ) {
			return translate( '%(serviceName)s: %(rate)s', {
				args: {
					serviceName: rateInfo.title,
					rate: formatCurrency( rateInfo.rate, 'USD' ),
				},
			} );
		}

		return '';
	}

	// Otherwise, just show the total
	return translate( 'Total rate: %(total)s', {
		args: {
			total: formatCurrency( total, 'USD' ),
		},
	} );
};
github Automattic / wp-calypso / client / my-sites / earn / memberships / index.jsx View on Github external
{
					args: {
						amount: formatCurrency( subscriber.plan.renewal_price, subscriber.plan.currency ),
						formattedDate: this.props.moment( subscriber.start_date ).format( 'll' ),
						total: formatCurrency( subscriber.all_time_total, subscriber.plan.currency ),
					},
				}
			);
		} else if ( subscriber.plan.renew_interval === '1 month' ) {
			return this.props.translate(
				'Paying %(amount)s/month since %(formattedDate)s. Total of %(total)s.',
				{
					args: {
						amount: formatCurrency( subscriber.plan.renewal_price, subscriber.plan.currency ),
						formattedDate: this.props.moment( subscriber.start_date ).format( 'll' ),
						total: formatCurrency( subscriber.all_time_total, subscriber.plan.currency ),
					},
				}
			);
		}
	}
	renderSubscriberActions( subscriber ) {
github Automattic / wp-calypso / client / my-sites / checkout / upsell-nudge / plan-upgrade-upsell / index.jsx View on Github external
{ translate(
								'Give the Premium plan a risk-free test drive with our {{u}}30-day Money Back Guarantee{{/u}}.',
								{
									components: { u: <u> },
								}
							) }
						<p></p>
						<p>
							<b>
								{ translate(
									'Upgrade to the Premium plan and access over 250 premium themes for just {{del}}%(fullPrice)s{{/del}} %(discountPrice)s more.',
									{
										components: { del: <del> },
										args: {
											bundleValue: formatCurrency( bundleValue, currencyCode, { precision: 0 } ),
											fullPrice: formatCurrency( planRawPrice, currencyCode, { stripZeros: true } ),
											discountPrice: formatCurrency( planDiscountedRawPrice, currencyCode, {
												stripZeros: true,
											} ),
										},
									}
								) }
							</del></b>
						</p>
					
					<div>
						<img src="{" alt="Website expert offering a support session">
					</div></u>
github Automattic / wp-calypso / client / blocks / subscription-length-picker / index.jsx View on Github external
export function myFormatCurrency( price, code, options = {} ) {
	const precision = CURRENCIES[ code ].precision;
	const EPSILON = Math.pow( 10, -precision ) - 0.000000001;

	const hasCents = Math.abs( price % 1 ) >= EPSILON;
	return formatCurrency( price, code, hasCents ? options : { ...options, precision: 0 } );
}
github Automattic / wp-calypso / client / blocks / upgrade-nudge-expanded / index.jsx View on Github external
render() {
		if ( ! this.props.currentPlan &amp;&amp; ! this.props.forceDisplay ) {
			return null;
		}

		const price = formatCurrency( this.props.plan.raw_price / 12, this.props.plan.currency_code );
		const features = this.props.planConstants
			.getPlanCompareFeatures()
			.filter( feature =&gt; feature !== this.props.highlightedFeature )
			.slice( 0, 6 );

		return (
			
				
				
				<div>
					</div>
github Automattic / wp-calypso / client / extensions / woocommerce / app / settings / shipping / shipping-zone / shipping-methods / utils.js View on Github external
export const getMethodSummary = ( method, currency ) => {
	if ( startsWith( method.methodType, 'wc_services' ) ) {
		return translate( 'Live rates calculated at checkout' );
	}

	switch ( method.methodType ) {
		case 'free_shipping':
			if ( ! method.requires ) {
				return translate( 'Free for everyone' );
			}

			return translate( 'Minimum order amount: %s', {
				args: [ formatCurrency( method.min_amount, currency ) || method.min_amount ],
			} );
		case 'flat_rate':
		case 'local_pickup':
			return formatCurrency( method.cost, currency ) || method.cost;
		default:
			return '';
	}
};
github Automattic / wp-calypso / client / my-sites / earn / memberships / index.jsx View on Github external
<li>
								<span>
									{ translate( 'Last 30 days', { context: 'Sum of earnings over last 30 days' } ) }
								</span>
								<span>
									{ formatCurrency( this.props.lastMonth, this.props.currency ) }
								</span>
							</li>
							<li>
								<span>
									{ translate( 'Next month', {
										context: 'Forecast for the subscriptions due in the next 30 days',
									} ) }
								</span>
								<span>
									{ formatCurrency( this.props.forecast, this.props.currency ) }
								</span>
							</li>
						
					
					<div>
						{ translate(
							'On your current plan, WordPress.com charges {{em}}%(commission)s{{/em}}.{{br/}} Additionally, Stripe charges are typically %(stripe)s. {{a}}Learn more{{/a}}',
							{
								args: {
									commission: '' + parseFloat( this.props.commission ) * 100 + '%',
									stripe: '2.9%+30c',
								},
								components: {
									em: <em>,
									br: <br>,
									a: (</em></div>
github Automattic / wp-calypso / client / my-sites / checkout / upsell-nudge / concierge-support-session / index.jsx View on Github external
/&gt;
								<span>
									{ translate( "{{b}}And more:{{/b}} Tell our experts what you'd like to cover.", {
										components: { b: <b> },
										comment: "This is a benefit listed on a 'Purchase a call with us' page",
									} ) }
								</b></span><b>
							
						

						<h4>
							{ translate(
								'Reserve a 45-minute "Quick Start" appointment, and save %(saveAmount)s if you sign up today.',
								{
									args: {
										saveAmount: formatCurrency( savings, currencyCode, { stripZeros: true } ),
									},
								}
							) }
						</h4>

						<p>
							<b>
								{ translate(
									'Book your call today for just {{del}}%(oldPrice)s{{/del}} %(price)s.',
									{
										components: { del: <del> },
										args: {
											oldPrice: formatCurrency( fullCost, currencyCode, { stripZeros: true } ),
											price: productDisplayCost,
										},
									}</del></b></p></b>
github Automattic / wp-calypso / client / my-sites / plan-features / header.jsx View on Github external
getDiscountTooltipMessage() {
		const { currencyCode, currentSitePlan, translate, rawPrice } = this.props;

		if ( planMatches( currentSitePlan.productSlug, { type: TYPE_FREE } ) ) {
			return translate( 'Price for the next 12 months' );
		}

		const price = formatCurrency( rawPrice, currencyCode );

		return translate(
			"You'll receive a discount from the full price of %(price)s because you already have a plan.",
			{ args: { price } }
		);
	}

@automattic/format-currency

JavaScript library for formatting currency.

GPL-2.0
Latest version published 9 months ago

Package Health Score

86 / 100
Full package analysis