nortakales / vs-code-qalc

Interactive scratchpad calculator for VS Code
MIT License
70 stars 2 forks source link

[Feature] Customize format number #11

Closed danilort closed 8 months ago

danilort commented 2 years ago

Qalc 0.1.8.

I suggest some changes to the settings.

Remove this:

// Turn this on to display commas in results ($1,000,000), or off to hide commas ($1000000)
qalc.output.displayCommas": true,

and add these two:

qalc.output.decimalSymbol": "."
qalc.output.digitGroupingSymbol": ","

Like Windows 10:

immagine

Now

Now I am much more free to choose the I prefer format.

English format (like qalc.output.displayCommas": true)

qalc.output.decimalSymbol": "."
qalc.output.digitGroupingSymbol": ","

immagine

English format (like qalc.output.displayCommas": false)

qalc.output.decimalSymbol": "."
qalc.output.digitGroupingSymbol": ""    //void string

immagine

Italian format

qalc.output.decimalSymbol": ","
qalc.output.digitGroupingSymbol": "."

immagine

Other format

qalc.output.decimalSymbol": "."
qalc.output.digitGroupingSymbol": " "   //space

immagine

Thank's for your job!

danilort commented 2 years ago

How to do

package.json

"qalc.output.digitGroupingSymbol": {
    "title": "Character that groups the digits",
    "type": "string",
    "default": ".",
    "description": "Character that groups the digits"
},
"qalc.output.decimalSymbol": {
    "title": "Character separating the decimals",
    "type": "string",
    "default": ",",
    "description": "Character separating the decimals"
}

settings.js

exports.temperatureShortcut = exports.localCurrencyCode = exports.localCurrencySymbol = exports.convertLocalCurrency = exports.upperExponentBound = exports.lowerExponentBound = exports.notation = exports.precision = exports.trimTrailingZeros = exports.displayCommas = exports.enabledLanguages = exports.maxAlignmentColumn = exports.alignResults = exports.resultsColor = exports.getComputedResultsDelimiter = exports.resultsDelimiter = exports.showResultsDelimiter = exports.digitGroupingSymbol = exports.decimalSymbol = void 0; 

const SEPARA_GRUPPI_CIFRE = "qalc.output.digitGroupingSymbol";     //DG
const SEPARA_DECIMALI = "qalc.output.decimalSymbol";     //DG

……………………..

function digitGroupingSymbol() {
    return getConfiguration(SEPARA_GRUPPI_CIFRE);
}
exports.digitGroupingSymbol = digitGroupingSymbol;

function decimalSymbol() {
    return getConfiguration(SEPARA_DECIMALI);
}
exports.decimalSymbol = decimalSymbol;

document.js

digitGroupingSymbol: settings_1.digitGroupingSymbol(),   
decimalSymbol: settings_1.decimalSymbol() 

decorator.js

digitGroupingSymbol: settings_1.digitGroupingSymbol(),  
decimalSymbol: settings_1.decimalSymbol() 

formatter.js

if (formatterSettings.trimTrailingZeros) 
{
   .................
}

//replace the decimal separator with temporary characters
output = output.replace(/\./, '#');

//add the digit group separator
output = output.replace(/\B(?<!\#\d*)(?=(\d{3})+(?!\d))/g, formatterSettings.digitGroupingSymbol);

//replace the decimal separator
output = output.replace(/\#/, formatterSettings.decimalSymbol);

return output;
ml-1 commented 8 months ago

@nortakales I'm really missing this feature. Would this be merged if it was made into a pull request or are there any parts that needs to be rewritten?

nortakales commented 8 months ago

I'll look into it this week. I think it should be fairly straightforward, I just want to make sure I honor existing settings or somehow migrate them to the new settings so I don't change things unexpectedly for existing users.

nortakales commented 8 months ago

Added these settings in version 0.3.0. Let me know if there are any issues.

Commit: https://github.com/nortakales/vs-code-qalc/commit/92ad4e6b9df17d4d8911e7b621fa7143726cdc7f