blacksmithgu / obsidian-dataview

A data index and query language over Markdown files, for https://obsidian.md/.
https://blacksmithgu.github.io/obsidian-dataview/
MIT License
7.06k stars 414 forks source link

Currency Formatting #1705

Open hrosenbrock opened 1 year ago

hrosenbrock commented 1 year ago

Dataview can easily handle numbers in the "database", but displaying them as currency with native DQL was very difficult. It would be helpful to have a formatter, like with dates, to allow currency values to be easily displayed in a table. In my private build, I created a very simple function specific to my use-case, but it could be easily extended to be more generic. It uses the standard Javascript currency formatter.

    export const moneyformat = new FunctionBuilder("moneyformat")
        .add1("number", (n) => {
          const formatter = Intl.NumberFormat( 'en-US', { style: 'currency', currency: 'USD' } );
          return formatter.format( n );
        })
        .add1("null", () => null)
        .vectorize(1, [0])
        .build();
tenten71 commented 1 year ago

This would be very helpful to me. Can you tell me where/how I would paste this? Does it go in my dataview block, in the dataview main.js, or somewhere else? Thanks.