-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding missing cents zeros #85
Open
douglasresende
wants to merge
4
commits into
price-format:master
Choose a base branch
from
douglasresende:fill-str-with-zeros
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
eb82db6
Adding missing cents zeros
douglasresende 2810632
Changing the test to verify if str include a DOT
douglasresende a7f3d5b
Calling method to fix cents just when start the priceformat
douglasresende f14bfcc
Fixing bug when get() is 0 and clearOnEmpty option is true
douglasresende File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,13 +131,9 @@ | |
|
||
// apply cents pontuation | ||
// This stops from adding a leading Zero '0.00' -> '.00' | ||
if (leadingZero) { | ||
if (leadingZero || integerVal !== "0") { | ||
formatted = integerVal + centsSeparator + centsVal; | ||
} else { | ||
if (integerVal !== "0") { | ||
formatted = integerVal + centsSeparator + centsVal; | ||
} | ||
else { | ||
formatted = centsSeparator + centsVal; | ||
} | ||
} | ||
|
@@ -227,6 +223,26 @@ | |
|
||
} | ||
|
||
// Fill cents missing | ||
function fix_cents_by_str(str) { | ||
if (str[str.length-3] != '.' && str[str.length-3] != ',') { // 1.11 # do nothing | ||
if (str[str.length-2] == '.' || str[str.length-2] == ','){ // 1.1 # fill with 1 zero | ||
str = str+"0"; | ||
} else { // 1 # fill with 2 zeroes | ||
str = str+"00"; | ||
} | ||
} | ||
return str; | ||
} | ||
function fix_cents() { | ||
var str = get(); | ||
var new_str = fix_cents_by_str(str); | ||
var price = fix_cents_by_str(price_format(str)); | ||
if (new_str != price) set(price); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this one, I think it should be |
||
var format = fix_cents_by_str(price_format('0', true)); | ||
if (price == format && new_str != '0' && new_str != '000' && clearOnEmpty) set(''); | ||
} | ||
|
||
// Formatted price as a value | ||
function price_it() { | ||
var str = get(); | ||
|
@@ -290,6 +306,7 @@ | |
|
||
// If value has content | ||
if (get().length > 0) { | ||
fix_cents(); | ||
price_it(); | ||
clear_prefix(); | ||
clear_suffix(); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Douglas,
I've faced the same issue as you did, and tried your pull request.
It seems that this curly brace needs to be removed as well, otherwise the script will break.