Our site is under maintenance and some features may not work as expected.

Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

GREP – add missing zeroes to prices

Return to Member Forum

  • Author
    Posts
    • #1241132

      Hello! I’m sure this is a super simple request that has probably been addressed before, bu the solution wasn’t jumping our from search results on the site or forum.

      I’m working on an XML generated catalog, and the prices were mistakenly exported without 2 decimal places if it would have been a zero. So I have some prices that are correct (145.52) and some that are whole numbers (135) and some that only have one decimal point (132.6). I need all of these to have 2 decimal places (and the decimal added if it was missing).

      What GREP find/change would solve for this?

      thank you, thank you, thank you!

    • #1241159
      David Blatner
      Keymaster

      Do the whole numbers also have a decimal point at the end? For example, 135.
      You should do a grep search (in find/change) for \d+\.[^\d]
      which means “look for one or more numbers followed by a dot, followed by anything that is not a number”

    • #1241169
      Aaron Troia
      Participant

      Hmm, do all the prices in InDesign have a dollar sign?

      Assuming all the numbers are prices I would break this down into two searches, one for missing decimal and zeros and the other to add the ending zero.

      First, finding the prices with missing decimal and zeros
      Find: ^\d+(?!\.)$
      Change: $0.00

      The second search to add the zero to prices that already have the first number after the decimal,
      Find: ^\d+\.\d$
      Change $00

      Please note in Change $0 is referring to a capture group (in this case this means everything found) from the Find expression and not a literal dollar sign and zero.

      If the numbers do have dollar signs throughout to signify they are prices, I might tweak the Find GREPs to include the dollar sign just to make sure the GREP searches are only finding the numbers that it should be.

      Before you run this on your entire document, make a copy of your file and test these out to make sure they are catching what they should. Let me know if anything needs adjusting.

      Aaron

    • #1241179

      the whole numbers do not have a decimal at the end, but are followed by either an en dash, forced line break, or end of paragraph.

    • #1241699

      thanks so much for this, Aaron! I had partial success.

      This didn’t find anyhting: ^\d+(?!\.)$ but removing the ^ and replacing with a £ worked (i have a mixture of GBP and Euro prices (no $ symbols for this file). But very oddly, it wouldn’t work when I used € symbol, even though I copied and pasted it from the page.

      The second search you provided didn’t find any results either, even when removing the ^ character.

      Any guesses?

    • #1241709
      Aaron Troia
      Participant

      Oh good, I’m glad you were able to at least get the first one working once you tweaked it.

      Oh! I was thinking US currency by default, but having that currency symbol does help make sure we only are changing the prices. Im also guessing that second GREP didnt work because I have the end of line symbol ($) thrown in there and you said something about having a mixture of En Dash, Forced Line Break (soft return), and End of Paragraph (hard return). Is there a space between the last number and these?

      Lets try this,
      Find: (?:€|£)\K(\d+\.\d)
      Change: $10

Viewing 5 reply threads
  • The forum ‘General InDesign Topics (CLOSED)’ is closed to new topics and replies.
Forum Ads