Skip to content
Fix Code Error

How do I display a decimal value to 2 decimal places?

March 13, 2021 by Code Error
Posted By: wows

When displaying the value of a decimal currently with .ToString(), it’s accurate to like 15 decimal places, and since I’m using it to represent dollars and cents, I only want the output to be 2 decimal places.

Do I use a variation of .ToString() for this?

Solution

decimalVar.ToString ("#.##"); // returns "" when decimalVar == 0

or

decimalVar.ToString ("0.##"); // returns "0"  when decimalVar == 0
Answered By: AlbertEin

Related Articles

  • How should I get the value of this input field?
  • paper-item - way to place value for paper-dropdown?
  • How do I expand the output display to see more…
  • How can I format a decimal to always show 2 decimal places?
  • Active tab issue on page load HTML
  • python 3.2 UnicodeEncodeError: 'charmap' codec can't…
  • Ember computed properties with arguments
  • Is it possible to apply CSS to half of a character?
  • How to convert number to words in java
  • Show/hide 'div' using JavaScript
  • Why not use Double or Float to represent currency?
  • How can I pass a wct test while rearranging children…
  • Having trouble with my nav bar/header, It used to…
  • Python: Float to Decimal conversion and subsequent…
  • How to round the double value to 2 decimal points?
  • Centering in CSS Grid
  • Format Column Data before passing to Vue Good-Table
  • Scraping text after a span in with Regex (and Requests)
  • Bind Select inside of table row from array not…
  • Siemens LOGO! PLC data in the wrong order
  • How does PHP 'foreach' actually work?
  • Float vs Decimal in ActiveRecord
  • What's the difference between Instant and LocalDateTime?
  • What are the undocumented features and limitations…
  • How to obtain the start time and end time of a day?
  • How to create a game over screen for a basic HTML/JS game?
  • Confused about the Visitor Design Pattern
  • My very first python program! An income tax calculator
  • Round a double to 2 decimal places
  • Difference between decimal, float and double in .NET?
  • How to truncate float values?
  • Using Auto Layout in UITableView for dynamic cell…
  • Ukkonen's suffix tree algorithm in plain English
  • Display number always with 2 decimal places in
  • Align input points with multiple variable lengths
  • Sorting 1 million 8-decimal-digit numbers with 1 MB of RAM
  • Get product variation description to display on…
  • Dollar cents axis in Altair
  • React google map is not updating
  • ember.js: using routes, templates and outlets to…
  • Ember.js Recommended Way to Remove Items From a…
  • How to add fade animation for this tab
  • When clicked, hide others and so on [Code optimisation]
  • How can I specify a display?
  • How to download and save an image in Android
  • How can I recover the return value of a function…
  • Simplest way to create Unix-like continuous pipeline…
  • How do I determine whether my calculation of pi is accurate?
  • Controlling number of decimal digits in print output in R
  • What represents a double in sql server?
  • Difference between variable declaration syntaxes in…
  • Limiting double to 3 decimal places
  • Form field border-radius is not working only on the…
  • Backbone.Marionette - Collection within…
  • center images with each other in logo carousel
  • How do I print my Java object without getting…
  • Chrome / Safari not filling 100% height of flex parent
  • Locust Performance different from time() function
  • Design DFA accepting binary strings divisible by a…
  • Regular expression to match numbers with or without…
  • Setting up and using Meld as your git difftool and mergetool
  • How to deal with floating point number precision in…
  • Javascript validate all checkboxes are selected
  • How do I represent a time only value in .NET?
  • Secure hash and salt for PHP passwords
  • Playing HTML5 video on fullscreen in android webview
  • Difference between numeric, float and decimal in SQL Server
  • How to generate a random string of a fixed length in Go?
  • How to round a number to n decimal places in Java
  • Discord.js "undefined" before first array object in embed
  • What encoding/code page is cmd.exe using?
  • HTML table with 100% width, with vertical scroll…
  • Why does C++ code for testing the Collatz conjecture…
  • How to get the system uptime in Windows?
  • center 3 items on 2 lines
  • Shopify price variation equation
  • Show users location on a struct MapView
  • Is floating point math broken?
  • How to specify line breaks in a multi-line flexbox layout?
  • Vue.js - How to properly watch for nested data
  • Convert double/float to string
  • What is the correct way to represent null XML elements?
  • IsNumeric gives unexpected results in excel/vba for…
  • Php mailer working with utf-8 locally but not on host
  • Backbone Model View: Switch between editing (via…
  • Get the decimal part from a double
  • RegEx match open tags except XHTML self-contained tags
  • How do SO_REUSEADDR and SO_REUSEPORT differ?
  • Select SQL Server database size
  • How to submit Polymer forms to PHP and display response
  • How to pass and change index of array in vue?
  • How to fix the deprecated…
  • How many values can be represented with n bits?
  • How to get the difference between two arrays of…
  • dynamically add and remove view to viewpager
  • How do i update a javascript variable as its value changes?
  • Undefined reference to 'vtable for ✘✘✘'
  • Why isn't my ember.js route model being called?
  • Reference — What does this symbol mean in PHP?
  • How to define a group of class pairs that have a…

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

How can I get my Twitter Bootstrap buttons to right align?

Next Post:

How do I see active SQL Server connections?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error