screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script> </head> <body> <h3>Vue Js Currency Input using Intl.NumberFormat</h3> <div id="app"> <label for="currency-input">Enter amount:</label> <div class="currency-input-container"> <span class="dollar-sign">$</span> <input type="text" v-model="amount" @input="formatCurrency" inputmode="numeric" pattern="[0-9]*" /> </div> <p>Formatted Currency: {{ result }}</p> </div> <script type="module"> const app = Vue.createApp({ data() { return { amount: 0, result: '' } }, methods: { formatCurrency() { if (this.amount === '') { this.result = ''; } else { this.amount = this.amount.replace(/[^0-9]/g, ''); const formatter = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', }); this.result = formatter.format(this.amount); } } } }); app.mount('#app'); </script> <style scoped> .currency-input-container { display: flex; align-items: center; } .dollar-sign { font-size: 24px; margin-right: 5px; font-weight: bold; } input { height: 40px; text-align: center; font-size: 24px; margin: 0; padding-left: 0; border: none; border-bottom: 2px solid #ccc; box-shadow: none; background-color: transparent; color: #333; transition: all 0.3s ease-in-out; font-family: Arial, Helvetica, sans-serif; } input:focus { outline: none; border-bottom-color: #007bff; } </style> </body> </html>