Regex fix

Posted on 2007-07-24
Last Modified: 2010-03-05
Hi all

I need this fixed it works as long as  $PintedDiscount doesn't end with "0" example 10, 20, 30, 40, 50

DONT WORK: $PintedDiscount = 0.20;

WORKS: $PintedDiscount = 0.25;

$PintedDiscount =~ s/^[0\.]+//;

print "$PintedDiscount%";

Question by:blnukem
    LVL 39

    Expert Comment

    What are you trying to do?

    Maybe you should just multiply $PintedDiscount *100
    LVL 48

    Accepted Solution

    As Adam is saying:

    $PintedDiscount = 0.20;
    print $PintedDiscount * 100 . "%\n";
    LVL 7

    Expert Comment

    $PintedDiscount =~ s/^[0\.]+(.*[1-9])$/$1/;

    Author Comment

    Thanks Tintin

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Suggested Solutions

    I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
    There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This video discusses moving either the default database or any database to a new volume.

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now