Git Product home page Git Product logo

excelnumberformat's Introduction

ExcelNumberFormat

.NET library to parse ECMA-376 number format strings and format values like Excel and other spreadsheet softwares.

Build status

Install via NuGet

If you want to include ExcelNumberFormat in your project, you can install it directly from NuGet

To install ExcelNumberFormat, run the following command in the Package Manager Console

PM> Install-Package ExcelNumberFormat

Usage

var format = new NumberFormat("#.##");
Console.WriteLine(format.Format(1234.56, CultureInfo.InvariantCulture));

Features

  • Parses and formats most custom number formats as expected: decimal, percent, thousands, exponential, fraction, currency, date/time, duration, text.
  • Supports multiple sections with conditions.
  • Formats values with relevant constants from CultureInfo.
  • Formats dates and durations using DateTime and TimeSpan values instead of numeric values like Excel.
  • Targets net20 and netstandard1.0 for max compatibility.

Formatting .NET types

The Format() method takes a value of type object as parameter. Internally, the value is cast or converted to a specific .NET type depending on the kind of number format:

Format Kind Example .NET type Conversion strategy
Number 0.00 double Convert.ToDouble()
Fraction 0/0 double Convert.ToDouble()
Exponent #0.0E+0 double Convert.ToDouble()
Date/Time hh:mm DateTime Convert.ToDateTime()
Duration [hh]:mm TimeSpan Cast to TimeSpan
General General (any) Convert.ToString()
Text ;;;"Text: "@ string Convert.ToString()

In case of errors, Format() returns the value from Convert.ToString().

TODO/notes

  • 'General' is formatted with .ToString() instead of Excel conventions.
  • No errors: Invalid format strings and incompatible input values are formatted with .ToString().
  • No color information.
  • Variable width space is returned as regular space.
  • Repeat-to-fill characters are printed once, not repeated.
  • No alignment hinting.
  • No date conditions.

excelnumberformat's People

Contributors

andersnm avatar igitur avatar

Watchers

James Cloos avatar Chandu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.