Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert string to currency format without casting to numerical value first

Tags:

vb.net

This code -

Convert.ToDecimal("28.9100000000000000").ToString("c")

will convert a string containing a decimal value to a nicely formatted currency value. Is there anyway to do this without first converting the string value to a decimal?

like image 680
ipr101 Avatar asked Mar 28 '12 11:03

ipr101


People also ask

How do I convert a string to currency in C?

Format a String to Currency With the ToString () Method in C The ToString () method is used to convert any data type to a string variable in C#. We can use the C string format specifier to format the resultant string variable in currency format.

Is it possible to format a number as a currency string?

Having to manually format a number as a currency string can be a tedious process. Even though this can be done oftentimes in a few lines of code, it's good practice to follow a standardized norm rather than hardcode it yourself, plus it's way easier for the developer writing the code.

How to convert a string variable to a numerical format?

LV _ STR = '123456789'. OTHERS = 2. WRITE : LV _ NUM. An other method to convert string variable to numerical format is the function WOSI_CONVERT_STRING_TO_NUM. Here the signature of this signature.

How do I convert numbers to currency strings in Python?

We'll be going over three alternate libraries and functions which allow us to convert numbers into currency strings: The locale module. The Babel module. The str.format () function. The locale module is already included in Python, though, we'll have to install Babel to use it.


1 Answers

A simple method that I use:

MoneyString = string.format("{0:C}",DecimalValue)
like image 112
Gatesay Avatar answered Sep 28 '22 18:09

Gatesay