Sponsored Content
Top Forums Shell Programming and Scripting trimm up the decimal places in output Post 302247438 by Ikon on Wednesday 15th of October 2008 05:41:24 PM
Old 10-15-2008
Code:
$something = 123.123456789
$something = sprintf("%.3f", $something);

now something = 123.123
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using the "Less Than" (-lt) switch on numbers with decimal places?

I'm using shell scripts to run some commands for the Configuration Management tool called Telelogic Synergy. I need to get the script to compare version numbers of files. The version numbers of the files are part of the actual filename, such as the following example: example_file-1... (7 Replies)
Discussion started by: Glyn_Mo
7 Replies

2. Shell Programming and Scripting

Four decimal places with awk

i have a script in which awk prints "($2-1700)/10000" and the answer is -0.07,but i want the answer in 4 decimal places. that is -0.0700. How can i sue awk to get my results in four decimal places (4 Replies)
Discussion started by: tomjones
4 Replies

3. Shell Programming and Scripting

Decimal places

i need to multiplay a number with 1.00.. so that the output should contain two decimal places at end.. for example... 236 * 1.00 = 236.00 245.8 * 1.00 = 245.80 but when i perform multiplication it shows output as. 236 245.8 can anyone help me to get the actual output of... (11 Replies)
Discussion started by: arunmanas
11 Replies

4. Shell Programming and Scripting

Arithmetic but keep 2 decimal places

I am trying to perform arithmetric, for example, to increment the value of variable $a (say 3) by 0.05 but when I tried the following expression let a=a+0.05 or a=$((a+0.05)) both returned 3.0499999999999998 I want to keep 2 decimal places so it returns 3.05 instead. (6 Replies)
Discussion started by: piynik
6 Replies

5. Shell Programming and Scripting

Bash Rounding to 2 decimal places

I have a number in a bash variable n, and want to round it to 2 decimal places. How can I do that? n=0.0867268 Need to have num=0.09 (1 Reply)
Discussion started by: kristinu
1 Replies

6. Shell Programming and Scripting

How to round up value upto 2 decimal places using sed?

Please help me in rounding up value upto 2 decimal palces using sed command #!/usr/bin/bash a=15.42 b=13.33 c=`echo $a*$b |bc -l` echo $c above code is is giving output "205.5486" but i want the output as "205.55" Thank you... (15 Replies)
Discussion started by: ranabhavish
15 Replies

7. Shell Programming and Scripting

Printing with decimal places from last 4 digits

I have input file like below, 201424|9999|OSS|622010|RGT|00378228764 201424|8888|OM|587079|RGT|00284329675 201424|7777|OM|587076|RGT|00128671024 201424|6666|OM|581528|RGT|00113552084 Output should be like below, should add decimal (.) from last 4 digits. ... (2 Replies)
Discussion started by: vinothsekark
2 Replies

8. Shell Programming and Scripting

Sum the fields with 6 decimal places - getting only 2 decimal places as output

I used the below script to Sum up a field in a file based on some unique values. But the problem is when it is summing up the units, it is truncating to 2 decimals and not 6 decimals as in the input file (Input file has the units with up to 6 Decimals – Sample data below, when the units in the 2... (4 Replies)
Discussion started by: brlsubbu
4 Replies

9. Shell Programming and Scripting

Calculate the constant e to 14+ decimal places using integer maths.

Hi guys... I am loving this integer maths thing. 64 bit systems are certainly easier than 32 bit, but hey, I don't intend to leave out my fav' platform. Using one of the 'Brothers' methods, URL inside the code. #!/bin/sh # # #!/usr/local/bin/dash # e_constant.sh # Brother's formula . #... (2 Replies)
Discussion started by: wisecracker
2 Replies
Data::FormValidator::Filters(3pm)			User Contributed Perl Documentation			 Data::FormValidator::Filters(3pm)

NAME
Data::FormValidator::Filters - Basic set of filters available in an Data::FormValidator profile. SYNOPSIS
use Data::FormValidator; %profile = ( filters => 'trim', ... ); my $results = Data::FormValidator->check( \%data, \%profile ); DESCRIPTION
These are the builtin filters which may be specified as a name in the filters, field_filters, and field_filter_regexp_map parameters of the input profile. Filters are applied as the first step of validation, possibly modifying a copy of the validation before any constraints are checked. RECOMMENDED USE
As a long time maintainer and user of Data::FormValidator, I recommend that filters be used with caution. They are immediately modifying the input provided, so the original data is lost. The few I recommend include "trim", which removes leading and trailing whitespace. I have this turned on by default by using CGI::Application::Plugin::ValidateRM. It's also generally safe to use the "lc" and "uc" filters if you need that kind of data transformation. Beyond simple filters, I recommend transforming the "valid" hash returned from validation if further changes are needed. PROCEDURAL INTERFACE
You may also call these functions directly through the procedural interface by either importing them directly or importing the whole :filters group. For example, if you want to access the trim function directly, you could either do: use Data::FormValidator::Filters (qw/filter_trim/); # or use Data::FormValidator::Filters (qw/:filters/); $string = filter_trim($string); Notice that when you call filters directly, you'll need to prefix the filter name with "filter_". THE FILTERS
FV_split use Data::FormValidator::Filters qw(FV_split); # Validate every e-mail in a comma separated list field_filters => { several_emails => FV_split(qr/s*,s*/), # Any pattern that can be used by the 'split' builtin works. tab_sep_field => FV_split(' '), }, constraint_methods => { several_emails => email(), }, With this filter, you can split a field into multiple values. The constraint for the field will then be applied to every value. This filter has a different naming convention because it is a higher-order function. Rather than returning a value directly, it returns a code reference to a standard Data::FormValidator filter. After successfully being validated the values will appear as an arrayref. FV_replace use Data::FormValidator::Filters qw(FV_replace); field_filters => { first_name => FV_replace(qr/Mark/,'Don'), }, FV_replace is a shorthand for writing simple find-and-replace filters. The above filter would be translated to this: sub { my $v = shift; $v =~ s/Mark/Don/; $v } For more complex filters, just write your own. trim Remove white space at the front and end of the fields. strip Runs of white space are replaced by a single space. digit Remove non digits characters from the input. alphanum Remove non alphanumeric characters from the input. integer Extract from its input a valid integer number. pos_integer Extract from its input a valid positive integer number. Bugs: This filter won't extract "9" from "a9+", it will instead extract "9+" neg_integer Extract from its input a valid negative integer number. Bugs: This filter will currently filter the case of "a9-" to become "9-", which it should leave it alone. decimal Extract from its input a valid decimal number. Bugs: Given "1,000.23", it will currently return "1.000.23" pos_decimal Extract from its input a valid positive decimal number. Bugs: Given "1,000.23", it will currently return "1.000.23" neg_decimal Extract from its input a valid negative decimal number. Bugs: Given "1,000.23", it will currently return "1.000.23" dollars Extract from its input a valid number to express dollars like currency. Bugs: This filter won't currently remove trailing numbers like "1.234". phone Filters out characters which aren't valid for an phone number. (Only accept digits [0-9], space, comma, minus, parenthesis, period and pound [#].) sql_wildcard Transforms shell glob wildcard (*) to the SQL like wildcard (%). quotemeta Calls the quotemeta (quote non alphanumeric character) builtin on its input. lc Calls the lc (convert to lowercase) builtin on its input. uc Calls the uc (convert to uppercase) builtin on its input. ucfirst Calls the ucfirst (Uppercase first letter) builtin on its input. SEE ALSO
o L<Data::FormValidator> o L<Data::FormValidator::Constraints> o L<Data::FormValidator::Filters::Image> - shrink incoming image uploads AUTHOR
Author: Francis J. Lacoste <francis.lacoste@iNsu.COM> Maintainer: Mark Stosberg <mark@summersault.com> COPYRIGHT
Copyright (c) 1999,2000 iNsu Innovations Inc. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms as perl itself. perl v5.14.2 2011-11-25 Data::FormValidator::Filters(3pm)
All times are GMT -4. The time now is 03:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy